ios - addChild 在 SpriteKit 中不起作用

标签 ios swift sprite-kit

我正在开发类似于以下内容的游戏: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/

相关文章:

ios - 后退按钮未显示在导航 Controller 中

ios - 如何在模拟器上运行的应用程序上将 lldb 作为独立调试器启动?

swift - 在 spritekit 中暂停游戏时显示菜单

javascript - 在 WKWebView(iOS,Swift)中使用本地 Javascript 源加载本地 HTML

ios - 使用从服务器检索的实际数据创建核心数据实体的最佳实践

ios - 无法将 JSON 值传输到 SecondViewController 中的标签

ios - 带有自定义占位符的自定义 UITextField

ios - 如何在播放音乐文件期间让动画在精确点工作?

ios - 我可以在 SpriteKit 中减慢或停止物理吗?

ios - 当应用程序进入后台时,如何在 SpriteKit 中正确暂停?