简体   繁体   中英

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. 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.

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
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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