Sprite Animation on ccTouchesBegin


Problem with continuous touch.

Hi, I’m new to Cocos2d-x, Lack of proper documentation making the development very hard… :frowning: :frowning: .
I’m trying to make a sequence animation, using CCSequence, on ccTouchesBegan, So each time I touch on the sprite it should animate.
My code:
void HelloWorld::ccTouchesBegan(cocos2d::CCSet pTouches, cocos2d::CCEventpEvent){
CCTouch *touch = (CCTouch *)pTouches~~>anyObject;
CCPoint location = touch~~>locationInView();
location = CCDirector::sharedDirector()>convertToGL;
>runAction(CCSequence::create(CCScaleBy::create(0.125f, 1.111f), CCScaleBy::create(0.125f, 0.9f)));
The problem with this approach is that, if I touch the sprite continuously(a bit fast too…), my sprite is scaling infinitely.
Please help me to solve this problem…
Thanks in advance…


First of all, if you want your sprite not to change its size when using Scale actions it is easier to use CCScaleTo.
And to answer you question : This happens, because with each touch you add an action to your sprite, which scales it up. If you do it fast enough, you add so many of these actions that you get these “unexpected” results.
Consider this example :

               125ms   125ms    125ms   125ms
Time :         -------|-------|-------|-------
FirstA :        scale++  scale--
SecondA :                     scale++ scale--

So you started scaling up, when your first action was still scaling down, so you get the “infinite” scaling.

Solution : It seems that you want to have only one scale action running on your sprite at a time. This can be achieved in two ways, by using a (CC)ActionManager.

  1. If you want to check if a specific action is running on a target :

    CCAction * getActionByTag (unsigned int tag, CCObject *pTarget);

  2. If you want to check if any actions at all are running on a target :

    unsigned int numberOfRunningActionsInTarget (CCObject *pTarget);


Thanks for the help.
i solved the problem by
if(sprite->numberOfRunningActions( )== 0){
//do some animation
In the reference i also found a useful function isDone(). But when I use,it generating some errors.