检查动画是否在cocos2d-x中运行

检查动画是否在cocos2d-x中运行,cocos2d-x,Cocos2d X,我目前正在学习cocos2D-x,正在制作一些精灵动画。 我的目标是,当单击按钮时,对象会向左移动,并带有一些动画。 现在,如果您快速单击多次,动画会立即发生,看起来熊是希望而不是行走 解决方案看起来很简单,我应该检查动画是否已经运行,以及是否不应该运行新动画 以下是我代码的一部分 CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("AnimBear.plist"); CCSpriteBatchNod

我目前正在学习cocos2D-x,正在制作一些精灵动画。
我的目标是,当单击按钮时,对象会向左移动,并带有一些动画。 现在,如果您快速单击多次,动画会立即发生,看起来熊是希望而不是行走

解决方案看起来很简单,我应该检查动画是否已经运行,以及是否不应该运行新动画

以下是我代码的一部分

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);

//Animation for bear walking    

bearAnimate = CCAnimate::create(bearWalkingAnimation);
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(“AnimBear.plist”);
CCSpriteBatchNode*spriteBatchNode=CCSpriteBatchNode::create(“AnimBear.png”,8);
此->添加子节点(spriteBatchNode,10);
CCArray*tempArray=new CCArray();
字符缓冲区[15];
对于(int i=1;i addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(buffer));
}
cAnimation*bearWalkingAnimation=cAnimation::create(tempArray,0.1f);
startAnimation=CCSprite::CreateWithPriteFrameName(“bear1.png”);
开始动画->设置位置(ccp(350,CCDirector::sharedDirector()->getWinSize().height/2-100);
启动->设置刻度(0.5f);
startAnimation->setTag(5);
//熊行走动画
bearAnimate=cAnimate::创建(bearWalkingAnimation);
这里bearAnimate是一个全局变量,我想知道它当前是否正在播放动画


我该怎么做呢?
谢谢。

假设运行操作的精灵是

CCSprite* bear;
我想你可以用

bear->numberOfRunningActions()
numberOfRunningActions()
返回一个无符号整数,因此要检查是否没有操作,您必须检查它是否返回
0

if ( bear -> numberOfRunningActions( ) == 0 ) {
   CCLOG( "No actions running." );
} else {
   CCLOG( "Actions running." );
} 
bearAnimate(CCAnimate)有一个方法来检查这一点

if (bearAnimate.isDone())
    doWhatYouWant();

该方法是从CCAction继承的。祝你好运。

你知道它在常规cocos2d中是如何实现的吗?@ThePoet我认为函数是相同的?