【发布时间】:2018-01-27 16:35:24
【问题描述】:
我有一个函数可以保存我场景中的所有节点,还有一个可以将它们添加回来(这些在应用程序打开时运行良好)。我遇到的问题是我将如何保存该数组,以便在应用程序重新打开时可以调用它。提前感谢您的帮助。
为我的节点添加了代码,以便更好地了解我想要完成的工作
let bubble = SKShapeNode(circleOfRadius: self.frame.size.width / 12)
bubble.position = testBubble.position
bubble.fillColor = SKColor.black
bubble.strokeColor = SKColor.black
bubble.name = "bubble"
bubble.physicsBody = SKPhysicsBody(circleOfRadius: bubble.frame.height / 2)
bubble.zPosition = 2
let bubbleLabel = SKLabelNode(text: "Bubble")
bubbleLabel.fontColor = UIColor.darkGray
bubbleLabel.fontSize = 10
bubbleLabel.fontName = "MarkerFelt-Thin"
bubbleLabel.position.y = bubble.frame.size.width / 2 -bubble.frame.size.height / 1.65
bubbleLabel.zPosition = 3
self.addChild(bubble)
bubble.addChild(bubbleLabel)
@objc func saveAllNodes() {
nodeArray.removeAll()
for node in self.children {
nodeArray.append(node)
}
}
@objc func addAllNodes() {
self.removeAllChildren()
for node in nodeArray {
self.addChild(node)
}
}
【问题讨论】:
标签: swift sprite-kit sknode