答案 0 :(得分:0)
根据实际的Swift 2.2,您可以找到:
@available(iOS 7.0, *)
public enum SKSceneScaleMode : Int {
case Fill /* Scale the SKScene to fill the entire SKView. */
case AspectFill /* Scale the SKScene to fill the SKView while preserving the scene's aspect ratio. Some cropping may occur if the view has a different aspect ratio. */
case AspectFit /* Scale the SKScene to fit within the SKView while preserving the scene's aspect ratio. Some letterboxing may occur if the view has a different aspect ratio. */
case ResizeFill /* Modify the SKScene's actual size to exactly match the SKView. */
}
您可以在viewController中执行此操作:
override func viewDidLoad() {
super.viewDidLoad()
if let scene = PreloadScene(fileNamed:"PreloadScene") {
// Configure the view.
let skView = self.view as! SKView
...
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFit
...
skView.presentScene(scene)
}
}
或从SKScene
转移到另一个SKScene
:
let transition = SKTransition.doorsOpenVerticalWithDuration(0.5)
let nextScene = MainScene(size: self.scene!.size)
nextScene.scaleMode = .AspectFit
self.scene?.view?.presentScene(nextScene, transition: transition)
答案 1 :(得分:0)
你可以将你的精灵缩放到蓝框。
func fitToBlueBox(node:SKSpriteNode, blueBox:SKSpriteNode) { let actualScale = min(blueBox.size.width/node.size.width, blueBox.size.height/node.size.height) node.setScale(actualScale); }