检查动画是否在cocos2d-x中运行 [英] Check If animation is running in cocos2d-x

查看:57
本文介绍了检查动画是否在cocos2d-x中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习cocos2D-x,并且正在做一些精灵动画.
我的目标是,单击按钮后,对象将向左移动并显示一些动画.现在,如果您快速单击多次,动画将立即发生,并且看起来熊在希望而不是走路.

I am currently learning cocos2D-x and am doing some sprite animation.
My Objective is that when a button is clicked the object moves to left with some animation. Now if you click multiple times rapidly the animation takes place immediately and it looks like the bear is hoping instead of walking.

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

The solution to it looks simple that I should check if animation is already running and if running the new animation should not take place.

以下是我的代码的一部分.

The following is a part 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);

//Animation for bear walking    

bearAnimate = CCAnimate::create(bearWalkingAnimation);

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

Here bearAnimate is a global variable and i wish to know if its currently playing the animation.

我该怎么做??
谢谢.

How do I do it.?
Thank you.

推荐答案

假设运行该操作的Sprite是

Assume the Sprite that runs the action is

CCSprite* bear;

我认为您可以使用类似的东西

I think you can use something like

bear->numberOfRunningActions()

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

numberOfRunningActions( ) returns an unsigned integer, so to check if there are no actions, you would have to check if it returns 0

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

这篇关于检查动画是否在cocos2d-x中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆