Hi,
I have hardcoded a MainMenu scene to 2042x1536. This works well across different devices where a certain perimeter is cropped in the iPhone simulators. But when I create a subclass (Welcome), it doesn’t inherit the aspectFill behaviour from the MainMenu superclass for the iPhone simulators (the iPads are fine), and stretches the background image to fill the SKView.
Why is this so? Is the anything I can do so that the Welcome class background image maintains the same hardcode behaviour from its MainMenu super class?
Thanks in advance,
Here are my codes:
import UIKit
import SpriteKit
import GameplayKit
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let scene = MainMenu(size: CGSize(width: 2048, height: 1536))
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
skView.ignoresSiblingOrder = true
scene.scaleMode = SKSceneScaleMode.aspectFill
skView.presentScene(scene)
}
override var shouldAutorotate: Bool {
return true
}
override var prefersStatusBarHidden: Bool {
return true
}
}
class MainMenu: SKScene {
let background = SKSpriteNode(imageNamed: “bg01”)
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(size: CGSize) {
super.init(size: size)
background.size.width = frame.size.width
background.position = CGPoint(x: size.width/2, y: size.height/2)
background.anchorPoint = CGPoint(x: 0.5, y: 0.5)
background.zPosition = 1
addChild(background)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in (touches) {
let location = touch.location(in: self)
let nodeTouched = atPoint(location)
if nodeTouched.name == "welcome" {
self.view?.presentScene(Welcome(size: self.size))
}
}
}
class Welcome: MainMenu {
override func didMove(to view: SKView) {
}
} // Welcome_Class closure
} // MainMenu_SuperClass closure