Remember that a CCAction object in cocos2d can only be used on one Sprite object

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.