Cocos2d-x Spritebatch node animation appears to be broken? cocos2d-x 2.0.3
Posted
by
George Host
on Game Development
See other posts from Game Development
or by George Host
Published on 2012-11-04T22:30:02Z
Indexed on
2012/11/04
23:19 UTC
Read the original article
Hit count: 766
Hi I have spent aprox 2 days trying to get this to work doing a google searches left and right and I did get it working except for sprite batch nodes.
So in my class I am able to load kuwalio_stand.png and I tested kuwalio_walk1.png and 2 and 3 from the FrameCache(). They work for sure 100%.
I run this code and it does not animate does anyone else have the same issue with sprite batch nodes?
cocos2d::CCSprite * player = Player::create();
player->setPosition(cocos2d::CCPointMake(0.0f,0.0f));
player->setDisplayFrame(cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("kuwalio_stand.png"));
player->setTag(PlayerTag);
cocos2d::CCAnimation * walk = cocos2d::CCAnimation::create();
cocos2d::CCSpriteFrame * walk1 = cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("kuwalio_walk1");
cocos2d::CCSpriteFrame * walk2 = cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("kuwalio_walk2");
cocos2d::CCSpriteFrame * walk3 = cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("kuwalio_walk3");
walk->addSpriteFrame(walk1);
walk->addSpriteFrame(walk2);
walk->addSpriteFrame(walk3);
cocos2d::CCAnimate * actionWalk = cocos2d::CCAnimate::create(walk);
cocos2d::CCRepeatForever * actionRepeat = cocos2d::CCRepeatForever::create(actionWalk);
walk->setDelayPerUnit(0.1f);
actionWalk->setDuration(10.1f);
this->runAction(actionRepeat);
// Change camera to a soft follow camera.
this->runAction(cocos2d::CCFollow::create(player));
mSceneSpriteBatchNode->addChild(player);
// Have the CCNode object run its virtual update function as fast as possible.
// Every frame for this layer.
this->scheduleUpdate();
Counter example without the sprite batch node...
cocos2d::CCSprite * sprite = cocos2d::CCSprite::create("kuwalio_walk1.png");
this->addChild(sprite,0);
sprite->setPosition(cocos2d::CCPointMake(60,60));
sprite->retain();
cocos2d::CCAnimation * actionAnimation = cocos2d::CCAnimation::create();
actionAnimation->setDelayPerUnit(0.01f);
actionAnimation->retain();
actionAnimation->addSpriteFrameWithFileName("kuwalio_walk1.png");
actionAnimation->addSpriteFrameWithFileName("kuwalio_walk2.png");
actionAnimation->addSpriteFrameWithFileName("kuwalio_walk3.png");
cocos2d::CCAnimate * a = cocos2d::CCAnimate::create(actionAnimation);
a->setDuration(0.10f);
cocos2d::CCRepeatForever * actionRepeat = cocos2d::CCRepeatForever::create(a);
sprite->runAction(actionRepeat);
© Game Development or respective owner