当我进入场景时如何设置场景的scalemode?
How to set the scalemode of a scene when I transit into it?
我的问题是当我试图切换到一个场景时,它的视图与我的开始场景不同。
问题是 - 我认为 - 缩放模式,所以我尝试设置缩放模式但它没有用。这是我尝试过的:
let skView = self.view! as SKView
let gameScene:GameScene = GameScene(size: self.frame.size)
gameScene.size = skView.bounds.size
gameScene.scaleMode = SKSceneScaleMode.ResizeFill
skView.presentScene(gameScene , transition: SKTransition.crossFadeWithDuration(1))
还有这个:
let gameScene = GameScene(size: self.size)
gameScene.scaleMode = SKSceneScaleMode.ResizeFill
self.view?.scene!.presentScene(gameScene , transition: SKTransition.crossFadeWithDuration(1))
而且我试过在didMoveToView()
函数中设置场景的缩放模式
None 这些方法有帮助,有帮助吗?
override func viewDidLoad() {
super.viewDidLoad()
if let scene = GameMenu(fileNamed:"GameMenu") {
// 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 = .ResizeFill
skView.presentScene(scene)
}
}
这是一个从一个场景过渡到另一个场景的示例。假设 GameMenu
是您的第一个场景,您想要过渡到 GameScene
。
在GameViewController中初始化GameMenu
大小:
override func viewDidLoad() {
super.viewDidLoad()
let scene = GameMenu(size: view.bounds.size)
// 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)
}
现在,你应该在第一个场景。什么时候过渡到GameScene
,根据需要添加如下代码:
let nextScene = GameScene(size: self.size)
scene?.view?.presentScene(nextScene, transition: SKTransition.crossFadeWithDuration(1))
现在一切都完成了,GameScene
出现了。如果您有任何问题,请检查此 sample project。
我的问题是当我试图切换到一个场景时,它的视图与我的开始场景不同。
问题是 - 我认为 - 缩放模式,所以我尝试设置缩放模式但它没有用。这是我尝试过的:
let skView = self.view! as SKView
let gameScene:GameScene = GameScene(size: self.frame.size)
gameScene.size = skView.bounds.size
gameScene.scaleMode = SKSceneScaleMode.ResizeFill
skView.presentScene(gameScene , transition: SKTransition.crossFadeWithDuration(1))
还有这个:
let gameScene = GameScene(size: self.size)
gameScene.scaleMode = SKSceneScaleMode.ResizeFill
self.view?.scene!.presentScene(gameScene , transition: SKTransition.crossFadeWithDuration(1))
而且我试过在didMoveToView()
函数中设置场景的缩放模式
None 这些方法有帮助,有帮助吗?
override func viewDidLoad() {
super.viewDidLoad()
if let scene = GameMenu(fileNamed:"GameMenu") {
// 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 = .ResizeFill
skView.presentScene(scene)
}
}
这是一个从一个场景过渡到另一个场景的示例。假设 GameMenu
是您的第一个场景,您想要过渡到 GameScene
。
在GameViewController中初始化GameMenu
大小:
override func viewDidLoad() {
super.viewDidLoad()
let scene = GameMenu(size: view.bounds.size)
// 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)
}
现在,你应该在第一个场景。什么时候过渡到GameScene
,根据需要添加如下代码:
let nextScene = GameScene(size: self.size)
scene?.view?.presentScene(nextScene, transition: SKTransition.crossFadeWithDuration(1))
现在一切都完成了,GameScene
出现了。如果您有任何问题,请检查此 sample project。