1

I am presenting a Game Controller/Game Scene programmatically from a View Controller (which passes a difficulty string to it) like so :

class GameController: UIViewController {

    var difficulty: String!

    override func loadView() {

        self.view = SKView(frame: UIScreen.main.bounds)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        let skView = self.view as! SKView

        let scene = GameScene(size: view.frame.size)
        // Set the scale mode to scale to fit the window
        scene.scaleMode = .aspectFill
        scene.difficulty = difficulty
        // Present the scene
        skView.presentScene(scene)

        skView.ignoresSiblingOrder = true
    }
}

However when the scene appears on the screen, all the content is "zoomed in" (SKSpriteNodes, SKLabels, etc.)

Does anyone have an idea about how to solve this?

Many thanks in advance.

PS: presenting via the SKS works OK, there is just a problem of SKLabel positioning on iPad. The problem with this method is that I haven't been able to find how to pass my custom variable difficulty to the scene via the SKS even though I changed its custom class to mine in the Storyboard so that should do too.

Herakleis
  • 513
  • 5
  • 21

1 Answers1

2

You really have 2 questions here. First is what's wrong with my current setup and secondly can I use the sks file and still pass data along.

to answer the second question, yes

if let gameScene = GameScene(fileNamed: "GameScene") {

    self.gameScene = gameScene
    self.gameScene.stage = 1
    self.gameScene.setupBasedOnStage()
    self.gameScene.scaleMode = .aspectFill
    self.view?.presentScene(self.gameScene, transition: SKTransition.reveal(with: .down, duration: 1.0))
}

You are able to set any custom property before revealing the page (in this case it's stage), and if you needed to you can call a setup function to load info/graphics based on the stage.

I use sks files for my scenes and setup them up like this all the time.

Ron Myschuk
  • 6,011
  • 2
  • 20
  • 32
  • Hey @Ron thank you for your reply but when presenting with the SKS I am unable to access the `var difficulty: String!` in my SKScene class (which is set as custom class in my SKS file). Is there anything special to set up ? – Herakleis Mar 15 '17 at 16:25
  • where is the variable setup? inside the class but outside a function? is it set to private? maybe post a little but of the scene class file to your question. also if you setup your string as var difficulty = "" you avoid having to treat it as an optional – Ron Myschuk Mar 15 '17 at 16:33
  • `.aspectFill` does it for me – bobobobo Mar 14 '21 at 13:43