cocos2d autoremove sprite after animation(cocos2d 动画后自动删除精灵)
问题描述
我是 cocos2d 和 iphone 开发的新手.我想创建一些动画,当一些带有它的精灵的物理对象被破坏时(例如显示飞溅).我想做一些我会说的对象:运行动画并在完成后摧毁自己.然后我想忘记这个对象 - 当动画完成时它应该自动销毁.最好的方法是什么?
I'm new to cocos2d and to iphone development at all. I want to create some animation, when some physical object with it's sprite is destroyed (for example to show a splash). And i want to to make some object i will say to: run the animation and destroy yourself when done. Then i want to forget about this object - it should be destroyed automatically when animation is finished. What is the best way to do it?
推荐答案
您可以使用 CCSequence 创建操作列表.你做的第一个动作应该是你的常规动作(或序列).第二个动作应该是 CCCallFuncND 动作,您可以在其中调用清理函数并传递给定的精灵.
You can use CCSequence to create a list of actions. The first action you do should be your regular action (or sequence). The second action should be CCCallFuncND action, where you can call a cleanup function and pass the given sprite.
在我的脑海中,我会做这样的事情:
Off the top of my head I'd do something like this:
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];
在清理功能中:
- (void) cleanupSprite:(CCSprite*)inSprite
{
// call your destroy particles here
// remove the sprite
[self removeChild:inSprite cleanup:YES];
}
您也可以在这两个动作之间添加另一个动作以用于销毁粒子动作,而不是在结束函数中调用它.
You could add in another action between these two actions as well for your destroy particle actions instead of calling that in the end function.
这篇关于cocos2d 动画后自动删除精灵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:cocos2d 动画后自动删除精灵
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01