SKSpriteNode 隐藏在 UI 背景图片下

SKSpriteNode hidden under a UI Background Image

我有一个 SKSpriteNode 可以正常工作。但是当我添加 UIImage 时,SKSpriteNode 隐藏在 UIImage 后面。我一直在试图找出原因,但我遇到了一些麻烦,似乎无法弄清楚我错过了什么让 SKSSpriteNode 出现在 UI 背景之上图像,而不是在它后面看不见的地方。任何帮助将不胜感激!

import UIKit
import SpriteKit

class GameViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    if let scene = GameScene(fileNamed:"GameScene") {
        // Configure the view.
        let skView = self.view as! SKView
        skView.showsFPS = true
        skView.showsNodeCount = true

        /* Sprite Kit applies additional optimizations to improve rendering performance */
        skView.ignoresSiblingOrder = true

        /* Set the scale mode to scale to fit the window */
        scene.scaleMode = .AspectFill

        skView.presentScene(scene)
    }
}

override func shouldAutorotate() -> Bool {
    return true
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return .AllButUpsideDown
    } else {
        return .All
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Release any cached data, images, etc that aren't in use.
}

override func prefersStatusBarHidden() -> Bool {
    return true
}

}

import SpriteKit
import SceneKit

class GameScene: SKScene, SKPhysicsContactDelegate {


var blueBall:SKSpriteNode!

override func didMoveToView(view: SKView) {


    self.physicsWorld.gravity = CGVectorMake(0.0, -5.0)
    self.physicsWorld.contactDelegate = self

    blueBall = SKSpriteNode( imageNamed: "ball")
    blueBall.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
    blueBall.physicsBody = SKPhysicsBody(circleOfRadius: blueBall.size.width / 1.5 )

    blueBall.physicsBody!.dynamic = true
    blueBall.physicsBody!.allowsRotation = false

    self.addChild(blueBall)
}

override func touchesBegan(touches: Set<UITouch> , withEvent event: UIEvent?) {
    self.blueBall.physicsBody?.velocity = CGVectorMake(35, 0)
    self.blueBall.physicsBody?.applyImpulse(CGVectorMake(4, 10))
} 

}

抽签顺序使用 zPosition 属性:

In your case you will need to give the Sprite you want to be displayed in front a higher .zPosition value than the one to be displayed further back.

示例:ball.zPosition = 10


zPosition 定义:

节点相对于父节点的高度。

提示: 默认值为 0.0。正 z 轴投影向观察者,因此具有较大 z 值的节点更靠近观察者。