Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 初学者xcode swift精灵套件-按名称移除精灵崩溃_Ios_Xcode_Swift_Sprite - Fatal编程技术网

Ios 初学者xcode swift精灵套件-按名称移除精灵崩溃

Ios 初学者xcode swift精灵套件-按名称移除精灵崩溃,ios,xcode,swift,sprite,Ios,Xcode,Swift,Sprite,我正试着在一些精灵触底时移除它们。如果我不检查姓名,它会起作用,但它也会删除我的背景。当我尝试将名称添加到时,如果它崩溃了 func checkifbotsreachbottom() { for child in self.children { if (child.position.y == 0 && child.name == "botone") { self.removeChildrenInArray([child])

我正试着在一些精灵触底时移除它们。如果我不检查姓名,它会起作用,但它也会删除我的背景。当我尝试将名称添加到
时,如果它崩溃了

func checkifbotsreachbottom() {
    for child in self.children {

        if (child.position.y == 0 && child.name == "botone") {

            self.removeChildrenInArray([child])

        }
    }
}

这会崩溃,但如果我删除
child.name
部分,它不会崩溃。

self.children
返回
[AnyObject]
。如果您将其强制转换为
[SKNode]
,一切都应该正常:

func checkifbotsreachbottom(){
    for child in self.children as [SKNode] {

        if (child.position.y == 0 && child.name == "botone") {

            self.removeChildrenInArray([child])

        }
    }
}
尝试使用removeFromParent()

我使用的是xCode 6.0.1,它可以很好地处理这段代码。 性能是恒定的

override func update(currentTime: CFTimeInterval) {
    /* Called before each frame is rendered */


    for child in children{

        if(child.position.y < 0 && child.name == "ship"){
            child.removeFromParent()
        }
    }

}
覆盖函数更新(currentTime:CFTimeInterval){
/*在渲染每个帧之前调用*/
儿童中的儿童{
if(child.position.y<0&&child.name==“ship”){
child.removeFromParent()
}
}
}

欢迎使用堆栈溢出!如果您发现我的答案解决了您的问题,请勾选我答案旁边的复选标记,接受我的答案。