mirror of https://github.com/axmolengine/axmol.git
issue #1470:implement animation
This commit is contained in:
parent
0c4b5dd3e9
commit
4b969e35c8
|
@ -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<CCRGBAProtocol*>(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())
|
||||
|
|
|
@ -95,7 +95,6 @@ CCBValue* CCBValue::create(const void *pPointer)
|
|||
|
||||
int CCBValue::getIntValue()
|
||||
{
|
||||
CCLog("type is %d", mType);
|
||||
assert(mType == kIntValue);
|
||||
|
||||
return mValue.nValue;
|
||||
|
|
|
@ -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. */
|
||||
/*
|
||||
|
|
|
@ -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
|
|
@ -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);
|
||||
}
|
|
@ -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
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
e2979d2a6cf37624621cb54dbfc8e84a9f5a3666
|
||||
545c76af355dd3e2c6950e5ea44243aa85083c43
|
Loading…
Reference in New Issue