所以我正在制作一个落沙益智游戏,你必须让沙粒进入球门。在 Swift 2、iOS 9、xCode 7 更新之前,我的节点工作正常。但是现在,当我加载游戏时,它并没有正确加载所有节点。
以这个为例:(我把大部分我知道不是问题的细节都注释掉了,比如标签的位置和颜色)
override func didMoveToView(view: SKView) {
self.physicsWorld.gravity = CGVectorMake(0.0, -4.8) // Rate of Gravity is set here
// Background
bg = SKSpriteNode(texture: SKTexture(imageNamed: "settingBG.png"))
// position and size declared here
self.addChild(bg)
// Back Button
back = SKSpriteNode(texture: SKTexture(imageNamed: "back.png"))
// position and size declared here
back.name = "back"
self.addChild(back)
// Tutorial Toggle
tutorial = SKSpriteNode(texture: SKTexture(imageNamed: "tutorial.png"))
// position and size declared here
tutorial.name = "tutorial"
self.addChild(tutorial)
// High Scores
redLabel = SKLabelNode(fontNamed: "QuicksandBold-Regular")
// font size and color here
blueLabel = SKLabelNode(fontNamed: "QuicksandBold-Regular")
// font size and color here
yellowLabel = SKLabelNode(fontNamed: "QuicksandBold-Regular")
// font size and color here
// label positions here
redPoints = SKLabelNode(fontNamed: "QuicksandBold-Regular")
// font size and color here
bluePoints = SKLabelNode(fontNamed: "QuicksandBold-Regular")
// font size and color here
yellowPoints = SKLabelNode(fontNamed: "QuicksandBold-Regular")
// font size and color here
// set up variables in labels from UserDefaults
// points position here
self.addChild(redLabel)
self.addChild(redPoints)
self.addChild(blueLabel)
self.addChild(bluePoints)
self.addChild(yellowLabel)
self.addChild(yellowPoints)
// Level Selector
chooseLabel = SKLabelNode(fontNamed: "QuicksandBold-Regular")
// size and color
chooser = SKSpriteNode(texture: SKTexture(imageNamed: "levelSelector.png"), size: CGSize(width: 75, height: 75))
number = SKLabelNode(fontNamed: "QuicksandBold-Regular")
// size and color
leftArrow = SKSpriteNode(texture: SKTexture(imageNamed: "leftarrow.png"), size: CGSize(width: 70, height: 50))
rightArrow = SKSpriteNode(texture: SKTexture(imageNamed: "rightarrow.png"), size: CGSize(width: 70, height: 50))
highscore = SKLabelNode(text: "QuicksandBold-Regular")
// size and color
// text for labels
// positions for everything else
self.addChild(chooseLabel)
self.addChild(chooser)
self.addChild(number)
self.addChild(leftArrow)
self.addChild(rightArrow)
self.addChild(highscore)
}
这应该在加载时将所有节点渲染到屏幕上,但是,许多节点丢失了,并且在许多情况下,每次运行时丢失的节点都不同。
有什么见解吗?