如何在SKSpriteKit中为模拟器和物理设备格式化场景

时间:2016-05-30 19:24:43

标签: xcode sprite-kit xcode7 skspritenode skview

我在使用SKSpriteKit为简单游戏格式化场景时遇到问题。 在模拟器中,我的场景看起来就像我想要的那样,但在物理设备上却看不到。

This is what is looks like in the Simulator

This is what it looks like on my Ipad

一旦我在物理设备(我的iPad)上运行它,我得到的只是背景的放大图片。

这是我的GameViewController.swift

import UIKit
import SpriteKit
class GameViewController: UIViewController {

var scene: GameScene!

override func viewDidLoad() {
    super.viewDidLoad()

    //Configure the view
    let skView = view as! SKView
    skView.multipleTouchEnabled = false

    //Create and configure the scene
    //create scene within size of skview
    scene = GameScene(size: skView.bounds.size)
    scene.scaleMode = .AspectFill

    //present the scene
    skView.presentScene(scene)
}


override func shouldAutorotate() -> Bool {
    return true
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return .Landscape
    } 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
}
}

另外这是我的GameScene.swift

import SpriteKit

class GameScene: SKScene {

//////////////////////////////////////////////////////////////////////
//background
var background = SKSpriteNode(imageNamed: "Basketball")
//isStarted & GameOver
var isStarted = false
var isGameOver = false
//
var Ball: Basketball_Ball!
var Rim1: Rim!
var Rim2: Rim!
//////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////
func addBackground(){
    //background
    background.zPosition = 0
    background.size = self.frame.size
    background.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
    addChild(background)

}
/////////////////////////////////////////////////////////////////////
func addBall() {
    Ball = Basketball_Ball()
    addChild(Ball)
    Ball.loadAppearance()
}
/////////////////////////////////////////////////////////////////////
func addRims() {
    Rim1 = Rim()
    addChild(Rim1)
    Rim1.loadAppearance()

    Rim2 = Rim()
    addChild(Rim2)
    Rim2.loadAppearance_Rim2()
}
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
override func didMoveToView(view: SKView) {
    addBackground()
    addBall()
    addRims()
}
/////////////////////////////////////////////////////////////////////


override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
   /* Called when a touch begins */

    }

override func update(currentTime: CFTimeInterval) {
    /* Called before each frame is rendered */
}
}

问题在于我在GameViewController文件中使用scene.scaleMode吗?

我是否需要为我的资产文件夹中的每张图片上传不同的尺寸?

0 个答案:

没有答案