2016-07-02 5 views
0

Каков наилучший способ аспектного изображения в синей коробке? Игра основана на пикселях, поэтому я хотел бы также сохранить пиксельный вид.Scaling SpriteKit game

enter image description here

+0

... использовать режим Aspect Fit масштаб? – Knight0fDragon

+0

Я называю это self.view? Будет ли это масштабировать все узлы? – Latcie

ответ

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) 
+0

Почему-то AspectFit не дает мне почтового ящика и кажется точно таким же, как AspectFill. – Latcie

+0

Попробуйте добавить код на свой вопрос, чтобы лучше понять вашу проблему. –

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); 
}