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" (SKSpriteNode
s, SKLabel
s, 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.
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.