diff --git a/extensions/CCBReader/CCBAnimationManager.cpp b/extensions/CCBReader/CCBAnimationManager.cpp index 66624b80d6..9ba3bad7b1 100644 --- a/extensions/CCBReader/CCBAnimationManager.cpp +++ b/extensions/CCBReader/CCBAnimationManager.cpp @@ -184,7 +184,7 @@ CCBSequence* CCBAnimationManager::getSequence(int nSequenceId) // Refer to CCBReader::readKeyframe() for the real type of value CCActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKeyframe *pKeyframe1, const char *pPropName, CCNode *pNode) { - float duration = pKeyframe1->getTime() - pKeyframe0->getTime(); + float duration = pKeyframe1->getTime() - (pKeyframe0 ? pKeyframe0->getTime() : 0); if (strcmp(pPropName, "rotation") == 0) { @@ -325,8 +325,18 @@ void CCBAnimationManager::setAnimatedProperty(const char *pPropName, CCNode *pNo int opacity = ((CCBValue*)pValue)->getByteValue(); (dynamic_cast(pNode))->setOpacity(opacity); } + else if (strcmp(pPropName, "displayFrame") == 0) + { + ((CCSprite*)pNode)->setDisplayFrame((CCSpriteFrame*)pValue); + } + else if (strcmp(pPropName, "color") == 0) + { + ccColor3BWapper *color = (ccColor3BWapper*)pValue; + ((CCSprite*)pNode)->setColor(color->getColor()); + } else { + CCLog("unsupported property name is %s", pPropName); CCAssert(false, "unsupported property now"); } } @@ -489,7 +499,6 @@ void CCBAnimationManager::runAnimations(int nSeqId, float fTweenDuration) if (nodeBaseValues) { CCDictElement* pElement2 = NULL; - //CCLog("nodeBaseValues get value for key %d", pElement->getIntKey()); CCDICT_FOREACH(nodeBaseValues, pElement2) { if (seqNodePropNames.find(pElement2->getStrKey()) != seqNodePropNames.end()) diff --git a/extensions/CCBReader/CCBValue.cpp b/extensions/CCBReader/CCBValue.cpp index a4a72ad9f8..3be6398bc1 100644 --- a/extensions/CCBReader/CCBValue.cpp +++ b/extensions/CCBReader/CCBValue.cpp @@ -95,7 +95,6 @@ CCBValue* CCBValue::create(const void *pPointer) int CCBValue::getIntValue() { - CCLog("type is %d", mType); assert(mType == kIntValue); return mValue.nValue; diff --git a/extensions/CCBReader/CCNodeLoader.cpp b/extensions/CCBReader/CCNodeLoader.cpp index 227798f697..ef1c383ba2 100644 --- a/extensions/CCBReader/CCNodeLoader.cpp +++ b/extensions/CCBReader/CCNodeLoader.cpp @@ -534,9 +534,6 @@ CCSpriteFrame * CCNodeLoader::parsePropTypeSpriteFrame(CCNode * pNode, CCNode * CCString * spriteSheet = pCCBReader->readCachedString(); CCString * spriteFile = pCCBReader->readCachedString(); - CCLog("sprite file %s", spriteFile->getCString()); - CCLog("sprite sheet %s", spriteSheet->getCString()); - CCSpriteFrame *spriteFrame = NULL; if (spriteFile->length() != 0) { @@ -697,7 +694,7 @@ CCString * CCNodeLoader::parsePropTypeFontTTF(CCNode * pNode, CCNode * pParent, // CCString * ttfEnding = CCString::create(".ttf"); - // Fix me if it is wrong + // TODO Fix me if it is wrong /* If the fontTTF comes with the ".ttf" extension, prepend the absolute path. * System fonts come without the ".ttf" extension and do not need the path prepended. */ /* diff --git a/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsLayerLoader.h b/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsLayerLoader.h new file mode 100644 index 0000000000..7038cd9406 --- /dev/null +++ b/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsLayerLoader.h @@ -0,0 +1,18 @@ +#ifndef _ANIMATIONSTESTLAYERLOADER_H_ +#define _ANIMATIONSTESTLAYERLOADER_H_ + +#include "AnimationsTestLayer.h" +#include "CCNodeLoader.h" + +/* Forward declaration. */ +class CCBReader; + +class AnimationsTestLayerLoader : public cocos2d::extension::CCLayerLoader { + public: + CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(AnimationsTestLayerLoader, loader); + + protected: + CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(AnimationsTestLayer); +}; + +#endif diff --git a/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsTestLayer.cpp b/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsTestLayer.cpp new file mode 100644 index 0000000000..8769d080d4 --- /dev/null +++ b/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsTestLayer.cpp @@ -0,0 +1,57 @@ +#include "AnimationsTestLayer.h" +#include "CCBAnimationManager.h" + +USING_NS_CC; +USING_NS_CC_EXT; + +AnimationsTestLayer::AnimationsTestLayer() +: mAnimationManager(NULL) +{} + +AnimationsTestLayer::~AnimationsTestLayer() +{ + CC_SAFE_RELEASE_NULL(mAnimationManager); +} + +SEL_MenuHandler AnimationsTestLayer::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName) +{ + return NULL; +} + +SEL_CCControlHandler AnimationsTestLayer::onResolveCCBCCControlSelector(CCObject *pTarget, CCString*pSelectorName) { + CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onCCControlButtonIdleClicked", AnimationsTestLayer::onCCControlButtonIdleClicked); + CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onCCControlButtonWaveClicked", AnimationsTestLayer::onCCControlButtonWaveClicked); + CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onCCControlButtonJumpClicked", AnimationsTestLayer::onCCControlButtonJumpClicked); + CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onCCControlButtonFunkyClicked", AnimationsTestLayer::onCCControlButtonFunkyClicked); + + return NULL; +} + +bool AnimationsTestLayer::onAssignCCBMemberVariable(CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode) { + CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mAnimationManager", CCBAnimationManager *, this->mAnimationManager); + + return false; +} + +void AnimationsTestLayer::setAnimationManager(cocos2d::extension::CCBAnimationManager *pAnimationManager) +{ + CC_SAFE_RELEASE_NULL(mAnimationManager); + mAnimationManager = pAnimationManager; + CC_SAFE_RETAIN(mAnimationManager); +} + +void AnimationsTestLayer::onCCControlButtonIdleClicked(CCObject *pSender, CCControlEvent pCCControlEvent) { + mAnimationManager->runAnimations("Idle", 0.3f); +} + +void AnimationsTestLayer::onCCControlButtonWaveClicked(CCObject *pSender, CCControlEvent pCCControlEvent) { + mAnimationManager->runAnimations("Wave", 0.3f); +} + +void AnimationsTestLayer::onCCControlButtonJumpClicked(CCObject *pSender, CCControlEvent pCCControlEvent) { + mAnimationManager->runAnimations("Jump", 0.3f); +} + +void AnimationsTestLayer::onCCControlButtonFunkyClicked(CCObject *pSender, CCControlEvent pCCControlEvent) { + mAnimationManager->runAnimations("Funky", 0.3f); +} \ No newline at end of file diff --git a/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsTestLayer.h b/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsTestLayer.h new file mode 100644 index 0000000000..fd37933ad6 --- /dev/null +++ b/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsTestLayer.h @@ -0,0 +1,33 @@ +#ifndef _ANIMATIONSTESTLAYER_H_ +#define _ANIMATIONSTESTLAYER_H_ + +#include "cocos2d.h" +#include "cocos-ext.h" + +class AnimationsTestLayer +: public cocos2d::CCLayer +, public cocos2d::extension::CCBSelectorResolver +, public cocos2d::extension::CCBMemberVariableAssigner +{ +public: + CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(AnimationsTestLayer, create); + + AnimationsTestLayer(); + virtual ~AnimationsTestLayer(); + + virtual cocos2d::SEL_MenuHandler onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName); + virtual cocos2d::extension::SEL_CCControlHandler onResolveCCBCCControlSelector(cocos2d::CCObject * pTarget, cocos2d::CCString * pSelectorName); + virtual bool onAssignCCBMemberVariable(cocos2d::CCObject * pTarget, cocos2d::CCString * pMemberVariableName, cocos2d::CCNode * pNode); + + void onCCControlButtonIdleClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent); + void onCCControlButtonWaveClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent); + void onCCControlButtonJumpClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent); + void onCCControlButtonFunkyClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent); + + void setAnimationManager(cocos2d::extension::CCBAnimationManager *pAnimationManager); + +private: + cocos2d::extension::CCBAnimationManager *mAnimationManager; +}; + +#endif \ No newline at end of file diff --git a/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/HelloCocosBuilder/HelloCocosBuilderLayer.cpp b/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/HelloCocosBuilder/HelloCocosBuilderLayer.cpp index d40c3ba3bc..d1b69d3bee 100644 --- a/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/HelloCocosBuilder/HelloCocosBuilderLayer.cpp +++ b/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/HelloCocosBuilder/HelloCocosBuilderLayer.cpp @@ -7,6 +7,7 @@ #include "../MenuTest/MenuTestLayerLoader.h" #include "../ParticleSystemTest/ParticleSystemTestLayerLoader.h" #include "../ScrollViewTest/ScrollViewTestLayerLoader.h" +#include "../AnimationsTest/AnimationsLayerLoader.h" USING_NS_CC; USING_NS_CC_EXT; @@ -74,7 +75,7 @@ SEL_CCControlHandler HelloCocosBuilderLayer::onResolveCCBCCControlSelector(CCObj CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onMenuTestClicked", HelloCocosBuilderLayer::onMenuTestClicked); CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onSpriteTestClicked", HelloCocosBuilderLayer::onSpriteTestClicked); CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onButtonTestClicked", HelloCocosBuilderLayer::onButtonTestClicked); - //CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onLabelTestClicked", HelloCocosBuilderLayer::onLabelTestClicked); + CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onAnimationsTestClicked", HelloCocosBuilderLayer::onAnimationsTestClicked); CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onParticleSystemTestClicked", HelloCocosBuilderLayer::onParticleSystemTestClicked); CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onScrollViewTestClicked", HelloCocosBuilderLayer::onScrollViewTestClicked); @@ -101,8 +102,46 @@ void HelloCocosBuilderLayer::onButtonTestClicked(CCObject * pSender, cocos2d::ex this->openTest("TestButtons.ccbi", "TestButtonsLayer", ButtonTestLayerLoader::loader()); } -void HelloCocosBuilderLayer::onLabelTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) { - this->openTest("TestLabels.ccbi", "TestLabelsLayer", LabelTestLayerLoader::loader()); +void HelloCocosBuilderLayer::onAnimationsTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) { + // Load node graph (TestAnimations is a sub class of CCLayer) and retrieve the ccb action manager + CCBAnimationManager *actionManager = NULL; + + /* Create an autorelease CCNodeLoaderLibrary. */ + CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary(); + + ccNodeLoaderLibrary->registerCCNodeLoader("TestHeaderLayer", TestHeaderLayerLoader::loader()); + ccNodeLoaderLibrary->registerCCNodeLoader("TestAnimationsLayer", AnimationsTestLayerLoader::loader()); + + + /* Create an autorelease CCBReader. */ + cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary); + ccbReader->autorelease(); + + /* Read a ccbi file. */ + // Load the scene from the ccbi-file, setting this class as + // the owner will cause lblTestTitle to be set by the CCBReader. + // lblTestTitle is in the TestHeader.ccbi, which is referenced + // from each of the test scenes. + CCNode *animationsTest = ccbReader->readNodeGraphFromFile("TestAnimations.ccbi", this, &actionManager); + ((AnimationsTestLayer*)animationsTest)->setAnimationManager(actionManager); + + this->mTestTitleLabelTTF->setString("TestAnimations.ccbi"); + + CCScene * scene = CCScene::create(); + if(animationsTest != NULL) { + scene->addChild(animationsTest); + } + + /* Push the new scene with a fancy transition. */ + ccColor3B transitionColor; + transitionColor.r = 0; + transitionColor.g = 0; + transitionColor.b = 0; + + CCDirector::sharedDirector()->pushScene(CCTransitionFade::create(0.5f, scene, transitionColor)); + + + //this->openTest("TestAnimations.ccbi", "TestAnimationsLayer", AnimationsTestLayerLoader::loader()); } void HelloCocosBuilderLayer::onParticleSystemTestClicked(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) { diff --git a/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/HelloCocosBuilder/HelloCocosBuilderLayer.h b/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/HelloCocosBuilder/HelloCocosBuilderLayer.h index 3f1a427f02..4530796b48 100644 --- a/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/HelloCocosBuilder/HelloCocosBuilderLayer.h +++ b/samples/TestCpp/Classes/ExtensionsTest/CocosBuilderTest/HelloCocosBuilder/HelloCocosBuilderLayer.h @@ -36,7 +36,7 @@ class HelloCocosBuilderLayer void onMenuTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent); void onSpriteTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent); void onButtonTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent); - void onLabelTestClicked(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent); + 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); diff --git a/samples/TestCpp/proj.ios/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id b/samples/TestCpp/proj.ios/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id index fc5a9fd776..70df50979e 100644 --- a/samples/TestCpp/proj.ios/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/samples/TestCpp/proj.ios/TestCpp.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -e2979d2a6cf37624621cb54dbfc8e84a9f5a3666 \ No newline at end of file +545c76af355dd3e2c6950e5ea44243aa85083c43 \ No newline at end of file