6

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)

ielyamani
  • 17,807
  • 10
  • 55
  • 90

4 Answers4

4
  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

Danil Shaykhutdinov
  • 2,027
  • 21
  • 26
2

I had to manually add an image set named LauchImage in the Images.xcassets.

ielyamani
  • 17,807
  • 10
  • 55
  • 90
  • This reads as if you just added a file to a project folder and that solved the problem. I have the same issue and managed to solve it by adding a button in another view (absolutely no clue why that works) but I was hoping for a better solution since I don't need the button. – SuperCodeBrah Nov 08 '17 at 03:22
0

You need to resize your background node to match scene.

background.size = self.frame.size
Donn
  • 1,680
  • 14
  • 17
0

First go onto your Xcode project

click the .xcodeproj file

Then under deployment info there should be a checkbox that says requires full screen check this and then the whole screen should be used!

EDIT

You must also assign a launch screen it as it was full screen for me momentarily but stopped once I removed the launch screen, you can assign It just under the deployment info it is under

App Icons and Launch Images

even if you haven't created one Xcode usually creates one for you when you first make the project it should be under the name "main"

36Boxes
  • 53
  • 7