我有一个CCSprite
called sprite
那是一个孩子CCLayer
called movingLayer
它本身就是当前的子项CCLayer
运行我的游戏逻辑,所以它是self
在这种情况下。movingLayer
以永远重复的动作在屏幕上来回移动sprite
正在骑着它。我想要得到sprite
“下车”movingLayer
并“继续”到self
它可以自己执行一些操作。
当我尝试这样做时,我需要告诉movingLayer
去除sprite
and self
to add sprite.
这就是我所做的...
- (void)attack:(id)sender
{
[sprite stopAllActions];
[movingLayer removeChild:sprite cleanup:YES];
[self addChild:sprite z:1];
CGFloat distance = ccpDistance(sprite.position, ccp(sprite.position.x, -sprite.contentSize.height/2));
id goDown = [CCMoveTo actionWithDuration:distance/moveDuration position:ccp(sprite.position.x, -sprite.contentSize.height/2)];
id repeatDown = [CCRepeatForever actionWithAction:[CCSequence actions:[CCMoveTo actionWithDuration:0 position:ccp(sprite.position.x, sprite.contentSize.height/2+self.contentSize.height)], [CCMoveTo actionWithDuration:moveDuration position:ccp(sprite.position.x, -sprite.contentSize.height/2)], nil]];
id attackAction = [CCSequence actions:goDown, repeatDown, nil];
[sprite runAction:attackAction];
}
I think stopAllActions
是多余的,但这不是问题。如果我删除sprite
from movingLayer
在将其添加到之前self
我因访问僵尸而崩溃,如果我尝试将其添加到self
首先,我因尝试添加已添加的内容而崩溃。
您是否尝试过将清理设置为“否”?
或者,在将精灵从 movingLayer 中删除之前尝试保留它,然后在完成后释放它:
[sprite retain];
[movingLayer removeChild:sprite cleanup:YES];
[self addChild:sprite z:1];
[sprite release];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)