c/c++语言开发共享动画后cocos2d autoremove精灵

我是cocos2d和iphone开发的新手。 我想创建一些动画,当一些带有它的精灵的物理对象被破坏时(例如显示一个闪光)。 我想做一些我会说的对象:运行动画并在完成后摧毁自己。 然后我想忘记这个对象 – 它应该在动画结束时自动销毁。 最好的方法是什么?

    您可以使用CCSequence创建操作列表。 您要做的第一个动作应该是您的常规动作(或序列)。 第二个动作应该是CCCallFuncND动作,你可以调用一个清理函数并传递给定的精灵。

    在我的头顶我会做这样的事情:

    CCSprite* mySpriteToCleanup = [CCSprite spriteWithFile:@"mySprite.png"]; [self addChild:mySpriteToCleanup]; // ... do stuff // start the destroy process id action1 = [CCIntervalAction actionWithDuration:0]; // the action it sounds like you have written above. id cleanupAction = [CCCallFuncND actionWithTarget:self selector:@selector(cleanupSprite:) data:mySpriteToCleanup]; id seq = [CCSequence actions:action1, cleanupAction, nil]; [mySpriteToCleanup runAction:seq]; 

    并在清理function:

     - (void) cleanupSprite:(CCSprite*)inSprite { // call your destroy particles here // remove the sprite [self removeChild:inSprite cleanup:YES]; } 

    您可以在这两个操作之间添加另一个操作以及您的destroy粒子操作,而不是在end函数中调用它。

    方便的方法是使用自定义RemoveNode操作,删除正在运行的CCNode对象( CCSprite也是CCNode )。

     //Remove the node from parent and cleanup @interface RemoveNode : CCActionInstant {} @end @implementation RemoveNode -(void) startWithTarget:(id)aTarget { [super startWithTarget:aTarget]; [((CCNode *)target_) removeFromParentAndCleanup:YES]; } @end 

    将它放在CCSequence最后一个参数中。 例如,淡出后将删除精灵:

     [mySprite runAction:[CCSequence actions: [CCFadeOut actionWithDuration:0.5], [RemoveNode action], nil]]; 

      以上就是c/c++开发分享动画后cocos2d autoremove精灵相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/559641.html

      (0)
      上一篇 2021年1月27日
      下一篇 2021年1月27日

      精彩推荐