mirror of https://github.com/axmolengine/axmol.git
fixed #1838: Adding test for the new feature(Timeline callback & playing effect) of CocosBuilder.
This commit is contained in:
parent
80a268baf6
commit
8b466f12a2
|
@ -364,7 +364,7 @@ CCActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKey
|
|||
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
|
||||
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
|
||||
|
||||
return CCSkewTo::create(duration, x, y);
|
||||
return CCSkewTo::create(duration, x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -419,17 +419,16 @@ void CCBAnimationManager::setAnimatedProperty(const char *pPropName, CCNode *pNo
|
|||
|
||||
setRelativeScale(pNode, x, y, type, pPropName);
|
||||
}
|
||||
else if(strcmp(pPropName, "skew") == 0)
|
||||
{
|
||||
|
||||
else if(strcmp(pPropName, "skew") == 0)
|
||||
{
|
||||
// Get relative scale
|
||||
CCArray *value = (CCArray*)pValue;
|
||||
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
|
||||
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
|
||||
|
||||
pNode->setSkewX(x);
|
||||
pNode->setSkewY(y);
|
||||
}
|
||||
pNode->setSkewX(x);
|
||||
pNode->setSkewY(y);
|
||||
}
|
||||
else
|
||||
{
|
||||
// [node setValue:value forKey:name];
|
||||
|
@ -565,10 +564,11 @@ CCObject* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* cha
|
|||
CCArray *keyframes = channel->getKeyframes();
|
||||
int numKeyframes = keyframes->count();
|
||||
|
||||
for (int i = 0; i < numKeyframes - 1; ++i) {
|
||||
for (int i = 0; i < numKeyframes; ++i) {
|
||||
|
||||
CCBKeyframe *keyframe = (CCBKeyframe*)keyframes->objectAtIndex(i);
|
||||
float timeSinceLastKeyframe = keyframe->getTime() - lastKeyframeTime;
|
||||
lastKeyframeTime = keyframe->getTime();
|
||||
if(timeSinceLastKeyframe > 0) {
|
||||
actions->addObject(CCDelayTime::create(timeSinceLastKeyframe));
|
||||
}
|
||||
|
@ -578,12 +578,8 @@ CCObject* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* cha
|
|||
int selectorTarget = atoi(((CCString *)keyVal->objectAtIndex(1))->getCString());
|
||||
|
||||
if(jsControlled) {
|
||||
|
||||
stringstream ss;//create a stringstream
|
||||
ss << selectorTarget;//add number to the stream
|
||||
std::string callbackName = ss.str() + ":" + selectorName;
|
||||
CCCallFunc *callback = (CCCallFunc*)mKeyframeCallFuncs->objectForKey(callbackName.c_str());
|
||||
callback->retain();
|
||||
CCString* callbackName = CCString::createWithFormat("%d:%s", selectorTarget, selectorName.c_str());
|
||||
CCCallFunc *callback = (CCCallFunc*)(mKeyframeCallFuncs->objectForKey(callbackName->getCString()))->copy()->autorelease();
|
||||
|
||||
if(callback != NULL) {
|
||||
actions->addObject(callback);
|
||||
|
@ -597,7 +593,7 @@ CCObject* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* cha
|
|||
SEL_CallFuncN selCallFunc = 0;
|
||||
|
||||
CCBSelectorResolver* targetAsCCBSelectorResolver = dynamic_cast<CCBSelectorResolver *>(target);
|
||||
|
||||
|
||||
if(targetAsCCBSelectorResolver != NULL) {
|
||||
selCallFunc = targetAsCCBSelectorResolver->onResolveCCBCCCallFuncSelector(target, selectorName.c_str ());
|
||||
}
|
||||
|
@ -626,10 +622,11 @@ CCObject* CCBAnimationManager::actionForSoundChannel(CCBSequenceProperty* channe
|
|||
CCArray *keyframes = channel->getKeyframes();
|
||||
int numKeyframes = keyframes->count();
|
||||
|
||||
for (int i = 0; i < numKeyframes - 1; ++i) {
|
||||
for (int i = 0; i < numKeyframes; ++i) {
|
||||
|
||||
CCBKeyframe *keyframe = (CCBKeyframe*)keyframes->objectAtIndex(i);
|
||||
float timeSinceLastKeyframe = keyframe->getTime() - lastKeyframeTime;
|
||||
lastKeyframeTime = keyframe->getTime();
|
||||
if(timeSinceLastKeyframe > 0) {
|
||||
actions->addObject(CCDelayTime::create(timeSinceLastKeyframe));
|
||||
}
|
||||
|
@ -784,10 +781,10 @@ void CCBAnimationManager::runAnimationsForSequenceIdTweenDuration(int nSeqId, fl
|
|||
|
||||
if(seq->getSoundChannel() != NULL) {
|
||||
CCAction* action = (CCAction *)actionForSoundChannel(seq->getSoundChannel());
|
||||
if(action != NULL) {
|
||||
mRootNode->runAction(action);
|
||||
}
|
||||
}
|
||||
if(action != NULL) {
|
||||
mRootNode->runAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
mRunningSequence = getSequence(nSeqId);
|
||||
}
|
||||
|
|
|
@ -840,6 +840,7 @@ bool CCBReader::readCallbackKeyframesForSeq(CCBSequence* seq) {
|
|||
if(!numKeyframes) return true;
|
||||
|
||||
CCBSequenceProperty* channel = new CCBSequenceProperty();
|
||||
channel->autorelease();
|
||||
|
||||
for(int i = 0; i < numKeyframes; ++i) {
|
||||
|
||||
|
@ -850,18 +851,17 @@ bool CCBReader::readCallbackKeyframesForSeq(CCBSequence* seq) {
|
|||
|
||||
CCArray* value = CCArray::create();
|
||||
value->addObject(CCString::create(callbackName));
|
||||
stringstream ss;//create a stringstream
|
||||
ss << callbackType;//add number to the stream
|
||||
|
||||
value->addObject(CCString::create(ss.str()));
|
||||
value->addObject(CCString::createWithFormat("%d", callbackType));
|
||||
|
||||
CCBKeyframe* keyframe = new CCBKeyframe();
|
||||
keyframe->autorelease();
|
||||
|
||||
keyframe->setTime(time);
|
||||
keyframe->setValue(value);
|
||||
|
||||
if(jsControlled) {
|
||||
string callbackIdentifier;
|
||||
mActionManager->getKeyframeCallbacks()->addObject(CCString::create(ss.str()+":"+callbackName));
|
||||
mActionManager->getKeyframeCallbacks()->addObject(CCString::createWithFormat("%d:%s",callbackType, callbackName.c_str()));
|
||||
}
|
||||
|
||||
channel->getKeyframes()->addObject(keyframe);
|
||||
|
@ -889,18 +889,9 @@ bool CCBReader::readSoundKeyframesForSeq(CCBSequence* seq) {
|
|||
CCArray* value = CCArray::create();
|
||||
|
||||
value->addObject(CCString::create(soundFile));
|
||||
stringstream ss;//create a stringstream
|
||||
ss << pitch;//add number to the stream
|
||||
|
||||
value->addObject(CCString::create(ss.str()));
|
||||
|
||||
ss.flush();
|
||||
ss << pan;
|
||||
value->addObject(CCString::create(ss.str()));
|
||||
|
||||
ss.flush();
|
||||
ss << gain;
|
||||
value->addObject(CCString::create(ss.str()));
|
||||
value->addObject(CCString::createWithFormat("%f", pitch));
|
||||
value->addObject(CCString::createWithFormat("%f", pan));
|
||||
value->addObject(CCString::createWithFormat("%f", gain));
|
||||
|
||||
CCBKeyframe* keyframe = new CCBKeyframe();
|
||||
keyframe->setTime(time);
|
||||
|
|
|
@ -16,11 +16,15 @@ NS_CC_EXT_BEGIN
|
|||
return cccontrol_selector(METHOD); \
|
||||
}
|
||||
|
||||
#define CCB_SELECTORRESOLVER_CALLFUNC_GLUE(TARGET, SELECTORNAME, METHOD) if(pTarget == TARGET && strcmp(pSelectorName, SELECTORNAME) == 0) { \
|
||||
return callfuncN_selector(METHOD); \
|
||||
}
|
||||
|
||||
class CCBSelectorResolver {
|
||||
public:
|
||||
virtual ~CCBSelectorResolver() {};
|
||||
virtual SEL_MenuHandler onResolveCCBCCMenuItemSelector(CCObject * pTarget, const char* pSelectorName) = 0;
|
||||
virtual SEL_CallFuncN onResolveCCBCCCallFuncSelector(CCObject * pTarget, const char* pSelectorName) = 0;
|
||||
virtual SEL_CallFuncN onResolveCCBCCCallFuncSelector(CCObject * pTarget, const char* pSelectorName) { return NULL; };
|
||||
virtual SEL_CCControlHandler onResolveCCBCCControlSelector(CCObject * pTarget, const char* pSelectorName) = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -158,8 +158,8 @@ void CCNodeLoader::parseProperties(CCNode * pNode, CCNode * pParent, CCBReader *
|
|||
}
|
||||
case kCCBPropTypeFloatXY:
|
||||
{
|
||||
float * xy = this->parsePropTypeFloatXY(pNode, pParent, pCCBReader);
|
||||
if(setProp)
|
||||
float * xy = this->parsePropTypeFloatXY(pNode, pParent, pCCBReader);
|
||||
if(setProp)
|
||||
{
|
||||
this->onHandlePropTypeFloatXY(pNode, pParent, propertyName.c_str(), xy, pCCBReader);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "../ParticleSystemTest/ParticleSystemTestLayerLoader.h"
|
||||
#include "../ScrollViewTest/ScrollViewTestLayerLoader.h"
|
||||
#include "../AnimationsTest/AnimationsLayerLoader.h"
|
||||
#include "../TimelineCallbackTest/TimelineCallbackLayerLoader.h"
|
||||
|
||||
USING_NS_CC;
|
||||
USING_NS_CC_EXT;
|
||||
|
@ -78,7 +79,8 @@ SEL_CCControlHandler HelloCocosBuilderLayer::onResolveCCBCCControlSelector(CCObj
|
|||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onAnimationsTestClicked", HelloCocosBuilderLayer::onAnimationsTestClicked);
|
||||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onParticleSystemTestClicked", HelloCocosBuilderLayer::onParticleSystemTestClicked);
|
||||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onScrollViewTestClicked", HelloCocosBuilderLayer::onScrollViewTestClicked);
|
||||
|
||||
CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onTimelineCallbackSoundClicked", HelloCocosBuilderLayer::onTimelineCallbackSoundClicked);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -184,4 +186,9 @@ void HelloCocosBuilderLayer::onParticleSystemTestClicked(CCObject * pSender, coc
|
|||
void HelloCocosBuilderLayer::onScrollViewTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent)
|
||||
{
|
||||
this->openTest("ccb/ccb/TestScrollViews.ccbi", "TestScrollViewsLayer", ScrollViewTestLayerLoader::loader());
|
||||
}
|
||||
}
|
||||
|
||||
void HelloCocosBuilderLayer::onTimelineCallbackSoundClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent)
|
||||
{
|
||||
this->openTest("ccb/ccb/TestTimelineCallback.ccbi", "TimelineCallbackTestLayer", TimelineCallbackTestLayerLoader::loader());
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ class HelloCocosBuilderLayer
|
|||
void onAnimationsTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
void onParticleSystemTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
void onScrollViewTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
void onTimelineCallbackSoundClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
|
||||
private:
|
||||
cocos2d::CCSprite * mBurstSprite;
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef _TIMELINECALLBACK_TESTLAYERLOADER_H_
|
||||
#define _TIMELINECALLBACK_TESTLAYERLOADER_H_
|
||||
|
||||
#include "TimelineCallbackTestLayer.h"
|
||||
|
||||
class TimelineCallbackTestLayerLoader : public cocos2d::extension::CCLayerLoader {
|
||||
public:
|
||||
CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(TimelineCallbackTestLayerLoader, loader);
|
||||
|
||||
protected:
|
||||
CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(TimelineCallbackTestLayer);
|
||||
};
|
||||
|
||||
#endif /* _TIMELINECALLBACK_TESTLAYERLOADER_H_ */
|
|
@ -0,0 +1,48 @@
|
|||
#include "TimelineCallbackTestLayer.h"
|
||||
|
||||
USING_NS_CC;
|
||||
USING_NS_CC_EXT;
|
||||
|
||||
TimelineCallbackTestLayer::TimelineCallbackTestLayer()
|
||||
: _helloLabel(NULL)
|
||||
{}
|
||||
|
||||
TimelineCallbackTestLayer::~TimelineCallbackTestLayer()
|
||||
{
|
||||
CC_SAFE_RELEASE(_helloLabel);
|
||||
}
|
||||
|
||||
SEL_MenuHandler TimelineCallbackTestLayer::onResolveCCBCCMenuItemSelector(CCObject * pTarget, const char * pSelectorName) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SEL_CCControlHandler TimelineCallbackTestLayer::onResolveCCBCCControlSelector(CCObject * pTarget, const char * pSelectorName) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SEL_CallFuncN TimelineCallbackTestLayer::onResolveCCBCCCallFuncSelector(CCObject * pTarget, const char* pSelectorName)
|
||||
{
|
||||
CCB_SELECTORRESOLVER_CALLFUNC_GLUE(this, "onCallback1", TimelineCallbackTestLayer::onCallback1);
|
||||
CCB_SELECTORRESOLVER_CALLFUNC_GLUE(this, "onCallback2", TimelineCallbackTestLayer::onCallback2);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool TimelineCallbackTestLayer::onAssignCCBMemberVariable(CCObject * pTarget, const char * pMemberVariableName, CCNode * pNode) {
|
||||
CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "helloLabel", CCLabelTTF *, this->_helloLabel);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TimelineCallbackTestLayer::onCallback1(CCNode* sender)
|
||||
{
|
||||
// Rotate the label when the button is pressed
|
||||
this->_helloLabel->runAction(CCRotateBy::create(1,360));
|
||||
this->_helloLabel->setString("Callback 1");
|
||||
}
|
||||
|
||||
void TimelineCallbackTestLayer::onCallback2(CCNode* sender)
|
||||
{
|
||||
// Rotate the label when the button is pressed
|
||||
this->_helloLabel->runAction(CCRotateBy::create(1,-360));
|
||||
this->_helloLabel->setString("Callback 2");
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef _TIMELINE_TESTLAYER_H_
|
||||
#define _TIMELINE_TESTLAYER_H_
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "cocos-ext.h"
|
||||
|
||||
class TimelineCallbackTestLayer
|
||||
: public cocos2d::CCLayer
|
||||
, public cocos2d::extension::CCBSelectorResolver
|
||||
, public cocos2d::extension::CCBMemberVariableAssigner
|
||||
{
|
||||
public:
|
||||
CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(TimelineCallbackTestLayer, create);
|
||||
|
||||
TimelineCallbackTestLayer();
|
||||
virtual ~TimelineCallbackTestLayer();
|
||||
|
||||
virtual cocos2d::SEL_MenuHandler onResolveCCBCCMenuItemSelector(cocos2d::CCObject * pTarget, const char * pSelectorName);
|
||||
virtual cocos2d::extension::SEL_CCControlHandler onResolveCCBCCControlSelector(cocos2d::CCObject * pTarget, const char * pSelectorName);
|
||||
virtual cocos2d::SEL_CallFuncN onResolveCCBCCCallFuncSelector(CCObject * pTarget, const char* pSelectorName);
|
||||
virtual bool onAssignCCBMemberVariable(cocos2d::CCObject * pTarget, const char * pMemberVariableName, cocos2d::CCNode * pNode);
|
||||
|
||||
void onCallback1(CCNode* sender);
|
||||
void onCallback2(CCNode* sender);
|
||||
private:
|
||||
cocos2d::CCLabelTTF* _helloLabel;
|
||||
};
|
||||
|
||||
#endif /* _TIMELINE_TESTLAYER_H_ */
|
|
@ -0,0 +1 @@
|
|||
13382b4a2fc6364d425aedd849893d8de79f72fb
|
|
@ -0,0 +1 @@
|
|||
5a60849ce6d5a81e3d62587a6651eb1a7ed7d488
|
|
@ -1 +1 @@
|
|||
5e326e12903a5d84168a8bc4b8bc6735e1b4c1c8
|
||||
7bd1abbd3c1270c95196be7965f911815e7ba4c4
|
Loading…
Reference in New Issue