遇到GameScene.sks和GameScene.swift问题。我试图为我的项目添加标题屏幕,然后从那里开始下坡。标题屏幕工作正常,但问题是当我编辑Gameviewcontroller.swift时。
This is how it ends up looking when I re-add the gamescene.sks
在添加TitleScreen
之前,这是GameViewController.Swift到工作文件import UIKit
import SpriteKit
import GameplayKit
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let scene = GameScene(size: view.bounds.size)
let skView = view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
skView.ignoresSiblingOrder = true
scene.scaleMode = .resizeFill
skView.presentScene(scene)
}
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
if UIDevice.current.userInterfaceIdiom == .phone {
return .allButUpsideDown
} else {
return .all
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
override var prefersStatusBarHidden: Bool {
return true
}
}
这是在更改视图以首先加载标题屏幕之后:
import UIKit
import SpriteKit
import GameplayKit
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if let scene = titleScreen(fileNamed: "titleScreen") {
//Configure view
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
skView.ignoresSiblingOrder = true
// Set the scale mode to scale to fit the window
// scene.scaleMode = .aspectFill
scene.size = self.view.frame.size
// Present the scene
skView.presentScene(scene)
}
}
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
if UIDevice.current.userInterfaceIdiom == .phone {
return .allButUpsideDown
} else {
return .all
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
override var prefersStatusBarHidden: Bool {
return true
}
}
答案 0 :(得分:0)
我认为您可能没有配置GameScene实例......
scene.scaleMode = .resizeFill
只在你的gameviewcontroller中调用...是吗?
这意味着只有你的第一个场景被配置。
在标题场景中,只要您是presentScene
,就需要配置下一个场景......
func configureScene(_ scene: SKScene) -> SKScene {
scene.scaleMode = .resizeFill
scene.anchorPoint = CGPoint(x: 0.5, y: 0.5) // Or whatever you want..
scene.size = UIWindow().frame.size // Or whatever size you want.
return scene
}
实施:
// Where self is an SKScene...
self.presentScene(configureScene(desiredScene))
同样如WW所说,帧和场景大小不同,会影响一切的外观。