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

检查动画是否在cocos2d-x中运行,第1张

概述我正在学习cocos2D-x并正在做一些精灵动画. 我的目标是当单击一个按钮时,对象会向左移动一些动画. 现在,如果你快速点击多次,动画会立即发生,看起来熊似乎希望而不是走路. 它的解决方案看起来很简单,我应该检查动画是否已经在运行以及是否应该运行新动画. 以下是我的代码的一部分. CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFra 我正在学习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);

这里bearanimate是一个全局变量,我想知道它是否正在播放动画.

我该怎么做.感谢你.

假设运行该 *** 作的Sprite是
CCSprite* bear;

我想你可以用类似的东西

bear->numberOfRunningActions()

numberOfRunningActions()返回一个无符号整数,所以为了检查是否没有动作,你必须检查它是否返回0

if ( bear -> numberOfRunningActions( ) == 0 ) {   cclOG( "No actions running." );} else {   cclOG( "Actions running." );}
总结

以上是内存溢出为你收集整理的检查动画是否在cocos2d-x中运行全部内容,希望文章能够帮你解决检查动画是否在cocos2d-x中运行所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1085974.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存