嗯,我的目标是提取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()
返回true
,因为所有SKActions
都进入堆栈:
它们似乎冻结,因为如果我分配更多的动作,它们将一堆一堆地堆积起来而不会运行。所有断点(
[好吧,我的目标是提取SKScene的内容,然后对它们的节点运行一些操作:func loadSceneNodes(){let loadScene = SKScene(fileNamed:“ newScene.sks”)//读取内容...] >moveToParent
而不是在父节点上使用addChild
,以避免创建副本。确保isPaused
状态设置为false,您可能正在复制它的时间为true