我正在处理一个项目,SKNode 不会根据设备大小动态调整大小。
例子:
我希望第一张图片上发生的事情在第二张图片上发生。 有什么可以让这一切自动发生吗?
显示图像的当前尺寸:
background.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
background.size = CGSize(width: background.size.width / 5.5, height: background.size.height / 5.5)
游戏 View Controller :
import UIKit
import SpriteKit
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = false
skView.showsNodeCount = false
let scene = GameScene(size: skView.bounds.size)
scene.controller = self
scene.size = skView.bounds.size
/* 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)
}
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return .AllButUpsideDown
} else {
return .All
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
override func prefersStatusBarHidden() -> Bool {
return true
}
}
最佳答案
如果您希望在具有更大屏幕的设备上显示游戏时调整整个场景的大小,您只需打开 GameViewController.swift
并确保您使用的是 AspectFill
scene.scaleMode = .AspectFill
关于swift - SpriteKit 使图像适合屏幕,而不是拉伸(stretch)过去,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38912057/