简体   繁体   English

节点未在Swift 2和SpriteKit中加载纹理

[英]Nodes not loading textures in Swift 2 and SpriteKit

So I am making a sand falling puzzle game, where you have to get the sand particles into the goal. 因此,我正在制作一个落沙益智游戏,您必须将沙粒带入目标。 Before the Swift 2, iOS 9, xCode 7 updates, my nodes were working fine. 在Swift 2,iOS 9,xCode 7更新之前,我的节点工作正常。 But now, when I load the game, it doesn't properly load all of the nodes. 但是现在,当我加载游戏时,它无法正确加载所有节点。

Take this for example: (I commented out most of the details that I know aren't the problem, such as positioning and color of labels) 以此为例:(我注释掉了我知道不是问题的大多数细节,例如标签的位置和颜色)

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)


}

This should render all of the nodes onto the screen on load, however, many of the nodes are missing, and in many cases, the nodes that are missing differ on every run. 这将在加载时将所有节点呈现到屏幕上,但是,许多节点丢失了,并且在许多情况下,每次运行时丢失的节点都不同。

跑一

运行两个

Any insight? 有见识吗?

Try set the ZPosition to yours nodes, works to me. 尝试将ZPosition设置为您的节点,对我有用。

On my project i have this situation: 在我的项目中,我遇到这种情况:

let bg = SKSpriteNode(imageNamed: "careSceneBG2")
bg.zPosition = 0
...

let monster = SKSpriteNode(imageNamed: "fire")
monster.zPosition = 1
...

let item = SKSpriteNode(imageNamed: img)
item.zPosition = 2
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM