I am currently learning cocos2D-x and doing animation sprites.
My goal is that when a button is clicked, the object moves to the left with some animation. Now, if you click several times quickly, the animation happens immediately, and it looks like the bear hopes instead of walking.
The solution for it looks simple, that I have to check if the animation is running, and if a new animation should not start.
Below is the code of my code.
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("AnimBear.plist"); CCSpriteBatchNode* spriteBatchNode = CCSpriteBatchNode::create("AnimBear.png", 8); this->addChild(spriteBatchNode,10); CCArray *tempArray = new CCArray(); char buffer[15]; for (int i = 1; i <= 8 ; i++) { sprintf(buffer,"bear%i.png", i); tempArray->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(buffer)); } CCAnimation *bearWalkingAnimation = CCAnimation::create(tempArray,0.1f); startAnimation = CCSprite::createWithSpriteFrameName("bear1.png"); startAnimation->setPosition(ccp (350 , CCDirector::sharedDirector()->getWinSize().height/2 -100)); startAnimation->setScale(0.5f); startAnimation->setTag(5);
Here bearAnimate is a global variable, and I want to know if it is currently playing animation.
How can I do it?
Thanks.
source share