Hi all.
first, my English might be strange but I hope you do not mind.
I have no idea what is wrong in this problem below.
bool HelloWorld::init(){
...
setAnimation();
runAnimation();
...
}
void HelloWorld::setAnimation(){
CCSprite* pSprite = CCSprite::create("a.png");
CCAnimation* animation = CCAnimation::create();
for (int i = 1; i<5; i++) {
char szName[50] = {0};
sprintf(szName, "mainCharacterRun%d.png",i); // mainCharacterRun%d.png is filename
animation->addSpriteFrameWithFileName(szName);
}
animation->setDelayPerUnit(0.1);
animation->setLoops(-1);
CCAnimate* action = CCAnimate::create(animationRun);
action->setTag(kTagAction);
}
void HelloWorld::runAnimation(){
CCSprite* pSprite = (CCSprite*)this->getChildByTag(kTagSprite); // kTagSprite is pSprite's tag.
CCAnimate* action = (CCAnimate*)this->getActionByTag(kTagAction);
pSprite->runAction(action);
}
and error is Cocos2d: Assert failed: Argument must be non-nil
Assertion failed: (action != __null), function runAction, file /Applications/cocos2d-x-2.2.2/cocos2dx/base_nodes/CCNode.cpp, line 1007.
How to use getActionByTag?
if I do not have to use this, please give me an example. But Tag must be used.
please help me