Cocos2d iphone Cocos2D removeChildByTag
我正在制作我的第一个cocos2D游戏,我在tag上遇到了麻烦。我打算在我的Cocos2d iphone Cocos2D removeChildByTag,cocos2d-iphone,Cocos2d Iphone,我正在制作我的第一个cocos2D游戏,我在tag上遇到了麻烦。我打算在我的游戏玩家中添加许多精灵,所以我使用了[self addChild:sprite z:1 tag:aTag]其中aTag+=1每次我增加标记值时。因为每个精灵都应该有一个唯一的标记值。有时我想清除我游戏层中的所有子对象,所以我使用如下标记值移除这些精灵 for (int i=10; i<1000; i++) { CCNode *child = [self getChildByTag:i];
游戏玩家中添加许多精灵,所以我使用了[self addChild:sprite z:1 tag:aTag]代码>其中aTag+=1代码>每次我增加标记值时。因为每个精灵都应该有一个唯一的标记值。有时我想清除我游戏层中的所有子对象,所以我使用如下标记值移除这些精灵
for (int i=10; i<1000; i++) {
CCNode *child = [self getChildByTag:i];
if (child == nil)
NSLog(@"removeChildByTag: child not found!");
else{
NSLog(@"child removed");
[self removeChild:child cleanup:YES];
child=nil;
}
}
for(int i=10;i您可以使用
[自移除ChildByTag:aTag清理:是]
对于错误访问,请检查sprite是否为空或图像是否为空
#define SAFE_REMOVE(p) if (p) [p removeFromParentAndCleanup:YES];
// Remove the the tag
CCNode* node = [self getChildByTag:YOURTAGNAMEHERE];
if (node != nil)
{
SAFE_REMOVE(node);
}