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()
}
}
}
欢迎使用堆栈溢出!如果您发现我的答案解决了您的问题,请勾选我答案旁边的复选标记,接受我的答案。