Cocos2d iphone 如何确定精灵是否在层中
如果这听起来很琐碎,我很抱歉。我就是不明白。如何确定一个特定的精灵是否已经在层中?基本上,在决定是否将其添加到图层之前,我需要检查此选项。有很多方法:Cocos2d iphone 如何确定精灵是否在层中,cocos2d-iphone,cclayer,Cocos2d Iphone,Cclayer,如果这听起来很琐碎,我很抱歉。我就是不明白。如何确定一个特定的精灵是否已经在层中?基本上,在决定是否将其添加到图层之前,我需要检查此选项。有很多方法: if ( [ myNode.children indexOfObject:sprite ] == NSNotFound ) { // you can add the code here } 1) 试着抓住孩子 if (![layer getChild:sprite]) { // Your code } 2) 试着按标签抓到
if ( [ myNode.children indexOfObject:sprite ] == NSNotFound ) {
// you can add the code here
}
1) 试着抓住孩子
if (![layer getChild:sprite]) {
// Your code
}
2) 试着按标签抓到孩子
if (![layer getChildByTag:spriteTag]) {
// Your code
}
3) 检查sprite是否在子数组中(如@oology-answer)
if ([layer.children indexOfObject:sprite] == NSNotFound) {
// Your code
}