我正在开发类似于以下内容的游戏:https://itunes.apple.com/us/app/impossible-rush-hd/id964396464?mt=8
创建了一组具有不同颜色的球对象 ( Ball: SKNode )。每次球接触轮子时,我都会使用以下方法移除球:
ball.removeFromParent()
这工作正常,但之后我从数组中选择另一个随机球来显示并添加到场景中,但它不起作用。节点数显示 1,这是 Wheel 节点。
我最初调用了这个函数,它工作正常,但在下次从 didBeginContact 方法调用时不起作用。
func sendBall(){
var randomIndex = Int(arc4random_uniform(UInt32(self.ballsArray.count)))
ball = self.ballsArray[randomIndex]
addChild(ball) //This statement has no effect when its called second time.
}
我被困在这里了。有人可以帮帮我吗。
最佳答案
but doesn't work the next time when called from the didBeginContact method.
我们不能在 didBeginContact 中添加 child, 从 didSimulatePhysics 方法做
在 didBeginContact() 和 didSimulatePhysics() 中设置一个标志检查标志并调用 sendBall() 并重置标志 :)
关于ios - addChild 在 SpriteKit 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30999629/