I’m having trouble changing animations.
I have a class that represents a character in my game, it subclasses from CCNode. It contains an animNode (CCSpriteBatchNode) which contains a sprite (CCSprite).
The code from my init() function that relates to the heirarchy:
// Get something to give to the anim node.
CCAnimation *anim = this->info->getStandAnimation();
CCMutableArray *frames = anim->getFrames();
CC_ASSERT(frames->count() > 0);
CCSpriteFrame *fr = frames->getObjectAtIndex(0);
CCRect const & rect = fr->getRect();
CC_ASSERT( !CCSize::CCSizeEqualToSize(rect.size, CCSizeZero) );
this->animNode = CCSpriteBatchNode::batchNodeWithTexture( fr->getTexture() );
this->sprite = new CCSprite();
success = this->sprite->initWithBatchNode(
When my game start, it plays the stand animation, which works fine, but when I switch to my move animation I get
Assertion failed: (! m_bUsesBatchNode), function setTexture, file libs/cocos2dx/sprite_nodes/CCSprite.cpp, line 1090.
line 1090 for reference:
CCAssert(! m_bUsesBatchNode, “setTexture doesn’t work when the sprite is rendered using a CCSpriteSheet”);
CCSprite::setTexture(CCTexture2D*) at CCSprite.cpp:1090
CCSprite::setDisplayFrame(CCSpriteFrame*) at CCSprite.cpp:1026
CCAnimate::update(float) at CCActionInterval.cpp:2189
My “animation” code:
void CTFTeamMember::runAnimation(CCAnimation *anim, char const * const textureName, unsigned const times, CCFiniteTimeAction *postAnimAction)
(times != 0) || !postAnimAction,
"Can't have a post anim action if looping infinitely.");
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(textureName);
CCActionInterval *action = CCAnimate::actionWithAnimation(anim, false);
if (times < 1)
action = CCRepeatForever::actionWithAction(action);
else if (times > 1)
action = CCRepeat::actionWithAction(action, times);
CC_ASSERT(times > 0);
action = CCSequence::actionOneTwo(
What am I doing wrong?