Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make SKScene fill whole screen using Swift

I have the following in GameViewController.swift

class GameViewController: UIViewController {

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        println(self.view.frame.size)
        var skView:SKView = self.view as SKView
        if skView.scene == nil {
            skView.showsFPS = false
            skView.showsNodeCount = false

            // Create and configure the scene.
            var scene : SKScene = GameScene(size: skView.bounds.size)
            scene.scaleMode = SKSceneScaleMode.AspectFill

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

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

it prints :

(320.0,480.0)

How to make the GameScene fill the whole screen instead of leaving black bands at the top and bottom of the screen?

the code in GameScene.swift

class GameScene: SKScene {
    override func didMoveToView(view: SKView) {
        /* Setup your scene here */
        var background : SKSpriteNode = SKSpriteNode (imageNamed: "background.png")
        background.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2)
        self.addChild(background)
    }
}

background.png is an image of size 640x1138

The deployment target is iOS 7.1

I am using Xcode 6.0.1 (Beta)

like image 758
ielyamani Avatar asked Sep 19 '14 11:09

ielyamani


1 Answers

  1. Add a Launch Screen:

New File - iOS - User Interface - Launch Screen

  1. Set the name of your new launch screen in:

Project - General - Launch Screen File

  1. In GameViewController set

sceneNode.scaleMode = .resizeFill

like image 105
Danil Shaykhutdinov Avatar answered Oct 01 '22 05:10

Danil Shaykhutdinov