开发者

cocos2d remove sprite with action

I have this setup:

A layer has a sprite as a child. The sprite has this code in its init method:

id fadeOut = [CCFadeOut actionWithDuration:1.0f];
id death = [CCCallFunc actionWithTarget:self selector:@selector(die)];
se开发者_如何转开发lf.deathAction = [CCSequence actions:fadeOut, death, nil];
[self runAction:deathAction_];

The death action calls the sprite's 'die' method in which its status is changed to 'dead'.

On its update method the layer checks all children and removes the ones wich are 'dead' with:

[self removeChild:child cleanup:YES];

The problem is that the child sprite still has retaincount of 2 after this line. As I understand it is kept by CCCallFunc. If I omit this deathAction and instead remove the sprites that have zero opacity (when they are faded), the code is working and the dealloc method gets called.

How should I remove the sprite by using an action properly?


You don't show all of your code. But it seems you are keeping a reference to the action and your likely forgetting to release that.

retainCount is notoriously unreliable : link so please don't use it and certainly don't count on it to be accurate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜