我想爲GameScene.sks
中的場景製作背景。我在那裏有Tile Map Node
,但是當我在GameScene.swift
中設置背景時,圖片出現在我的紋理上。我想要在場景的後面。SpriteKit zPosition背景
這裏是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
}
我知道我可以在GameScene.sks中創建背景。但我想在代碼中使用它,所以我可以設置背景滾動的速度。 –