gpt4 book ai didi

ios - CCNode 删除不工作 Cocos2d

转载 作者:行者123 更新时间:2023-11-29 02:54:32 25 4
gpt4 key购买 nike

出于某种原因,我的 CCNode 上的删除功能在动画运行后不起作用。

我在点击时添加一个 CCNode,运行动画然后运行删除功能。

         // loads the Coin
CCNode* coin = [CCBReader load:@"heros/coin"];
coin.name =@"coin";
// position
coin.position = ccpAdd(_touchNode.position, ccp(0, 0));

//Add to Parent
[_touchNode addChild:coin z:-1];

id action1 = [CCActionMoveTo actionWithDuration:0.7f position:ccpAdd(_touchNode.position, ccp(0, 200))];
id action2 = [CCActionMoveTo actionWithDuration:0.7f position:ccpAdd(_touchNode.position, ccp(0, 100))];
CCActionCallFunc *callAfterMoving = [CCActionCallFunc actionWithTarget:self selector:@selector(cleanupSprite:)];
[coin runAction: [CCActionSequence actions:action1, action2, callAfterMoving, nil]];

使用以下删除函数会产生崩溃错误,其中显示This node does not contain the specified child

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

用下面的delete也不行

- (void) cleanupSprite:(CCNode*)inSprite
{
// call your destroy particles here
// remove the sprite
[self removeChildByName:@"coin" cleanup:YES];
}

最佳答案

self 不包含 coin,_touchNode 包含。在您的回调中执行此操作:

[_touchNode removeChildByName:@"coin" cleanup:YES];

关于ios - CCNode 删除不工作 Cocos2d,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24079476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com