我想在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
}
答案 0 :(得分:0)
1
场景中z位置最小?如果是,请尝试将ignoresSiblingOrder
的{{1}}属性设置为SKView
。另外,我建议您至少阅读SKScene和SKNode文件。一般而言SpriteKit documentation。