我的目标是当单击一个按钮时,对象会向左移动一些动画.
现在,如果你快速点击多次,动画会立即发生,看起来熊似乎希望而不是走路.
它的解决方案看起来很简单,我应该检查动画是否已经在运行以及是否应该运行新动画.
以下是我的代码的一部分.
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);
这里bearanimate是一个全局变量,我想知道它是否正在播放动画.
我该怎么做.感谢你.
假设运行该 *** 作的Sprite是CCSprite* bear;
我想你可以用类似的东西
bear->numberOfRunningActions()
numberOfRunningActions()返回一个无符号整数,所以为了检查是否没有动作,你必须检查它是否返回0
if ( bear -> numberOfRunningActions( ) == 0 ) { cclOG( "No actions running." );} else { cclOG( "Actions running." );}总结
以上是内存溢出为你收集整理的检查动画是否在cocos2d-x中运行全部内容,希望文章能够帮你解决检查动画是否在cocos2d-x中运行所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)