Remember that a CCAction object in cocos2d can only be used on one Sprite object
In cocos2d, you often need to apply an action to multiple Sprites to achieve the same effect.
The following code is often used:
CCMoveTo * move =[CCMoveTo actionWithDuration:DESK_ANIMATE_TIME position:point];[deskImage runAction:move]; [HeadImageSprite runAction:move]; [TipsSprite runAction:move];
This code will cause crash because CCMTo is an asynchronous operation applied on Sprite,
[deskImage runAction:move]
After runAction is called
[HeadImageSprite runAction: move]; the life cycle of an action is different from that defined in the action variable. It must be completed after the action is executed by sprite, this is not controlled by our code. Therefore, an action cannot be applied to multiple Sprite instances.
The improvement method is as follows:
CCMoveTo * move =[CCMoveTo actionWithDuration:DESK_ANIMATE_TIME position:point];[deskImage runAction:move]; [HeadImageSprite runAction:[move copy]]; [TipsSprite runAction:[move copy]];
We make a copy of the action, copy it, and then apply it to other Sprite objects.