2016-08-12 53 views
1

我正在開發一個項目,並且SKNodes沒有根據設備大小動態調整大小。SpriteKit使圖像適合屏幕,而不是延伸過去

例子:

Image one enter image description here

我想第一個圖像上所發生的事情第二次發生。 有沒有什麼可以使這種情況自動發生?顯示圖像

電流大小:

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) 

GameViewController:

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

回答

0

如果您想在呈現上裝置有一個更大的屏幕,你只需要打開遊戲中你的整個場景來調整GameViewController.swift並確保您使用AspectFill

scene.scaleMode = .AspectFill 
+0

我已經在我的GameViewController中有這行代碼..很奇怪。也許它被忽略了? @appzYourLife –