SpriteKit zPosition背景

时间:2017-08-23 18:05:40

标签: ios swift xcode sprite-kit

我想在GameScene.sks中为场景制作背景。我有Tile Map Node,但是当我在GameScene.swift中设置背景时,图片就在我的纹理上。我想在场景的背面。

以下是GameScene.swift的代码:

import SpriteKit

class GameScene: SKScene {
    var background = SKSpriteNode(imageNamed: "BackGround")`
    override func didMove (to view: SKView) {
        background.zPosition = 1
        background.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
        addChild(background)
    }
}

以下是GameViewController.swift的代码:

import UIKit
import SpriteKit

class GameViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    if let view = self.view as! SKView? {
        // Load the SKScene from 'GameScene.sks'
        if let scene = SKScene(fileNamed: "GameScene") {
            // Set the scale mode to scale to fit the window
            scene.scaleMode = .aspectFill
            // Present the scene
            view.presentScene(scene)
        }
        view.ignoresSiblingOrder = true

        view.showsFPS = true
        view.showsNodeCount = true
    }
}

override var prefersStatusBarHidden: Bool {
    return true
}

1 个答案:

答案 0 :(得分:0)

1场景中z位置最小?如果是,请尝试将ignoresSiblingOrder的{​​{1}}属性设置为SKView。另外,我建议您至少阅读SKSceneSKNode文件。一般而言SpriteKit documentation