SKAction 对儿童的奇怪行为
Weird behavior of SKAction on children
好吧,我的目标是提取一个 SKScene
的内容,然后 运行 对他们的节点进行一些操作:
func loadSceneNodes() {
let loadedScene = SKScene(fileNamed: "newScene.sks")
// Reads the content of the "Content" node in the newScene.sks
let content = loadedScene!.childNode(withName: "Content") as! SKSpritenode
// I move the content to self
// (THANKS Knight0fDragon for suggestion)
content.move(toParent: self)
// Forces the unpause
self.isPause = false
// Try to run a test action on the node
content.run(.rotate(byAngle: 90, duration: 2.0)) {
print("DONE")
}
print(content.hasActions()) // DEBUG -> it prints TRUE
}
发生的情况是我成功阅读了内容并显示在场景中,但是即使 hasActions()
结果 true
也没有显示操作。
通过使用断点和调试控制台,我发现了一些非常有趣的东西。 content.hasActions()
returns true
因为所有 SKActions
都进入堆栈:
它们看起来像冻结了,因为如果我分配更多的动作,它们将一个接一个地堆叠起来而不会 运行。
只有 一旦我退出 断点(或者我是否暂停然后通过 xCode 播放应用程序)一切都会被执行。就像应用程序一样"needs"刷新一下。
在您的 sknode 上使用 moveToParent
而不是在您的父节点上使用 addChild
以避免创建副本的需要。
确保 isPaused
状态设置为 false,您可能在它为 true 的时候复制
好吧,我的目标是提取一个 SKScene
的内容,然后 运行 对他们的节点进行一些操作:
func loadSceneNodes() {
let loadedScene = SKScene(fileNamed: "newScene.sks")
// Reads the content of the "Content" node in the newScene.sks
let content = loadedScene!.childNode(withName: "Content") as! SKSpritenode
// I move the content to self
// (THANKS Knight0fDragon for suggestion)
content.move(toParent: self)
// Forces the unpause
self.isPause = false
// Try to run a test action on the node
content.run(.rotate(byAngle: 90, duration: 2.0)) {
print("DONE")
}
print(content.hasActions()) // DEBUG -> it prints TRUE
}
发生的情况是我成功阅读了内容并显示在场景中,但是即使 hasActions()
结果 true
也没有显示操作。
通过使用断点和调试控制台,我发现了一些非常有趣的东西。 content.hasActions()
returns true
因为所有 SKActions
都进入堆栈:
它们看起来像冻结了,因为如果我分配更多的动作,它们将一个接一个地堆叠起来而不会 运行。 只有 一旦我退出 断点(或者我是否暂停然后通过 xCode 播放应用程序)一切都会被执行。就像应用程序一样"needs"刷新一下。
在您的 sknode 上使用 moveToParent
而不是在您的父节点上使用 addChild
以避免创建副本的需要。
确保 isPaused
状态设置为 false,您可能在它为 true 的时候复制