动画完成后的cocos2d的autoremove的精灵 [英] cocos2d autoremove sprite after animation

查看:150
本文介绍了动画完成后的cocos2d的autoremove的精灵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的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的autoremove的精灵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆