I am really struggling to get sprites to rearrange themselves when the device is orientated from portrait to landscape and vice-vera. I have the following check on the ViewController:
override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {
let test1 = Menu()
switch UIDevice.current.orientation{
case .portrait : test1.setUpScene()
case .portraitUpsideDown : test1.setUpScene()
case .landscapeLeft : test1.setUpScene()
case .landscapeRight : test1.setUpScene()
default: break
}
}
This then launches the same checks as when the page is loaded, but none of the expected changes are made:
let backButtonPositionPortrait = CGPoint(x: ScreenSize.width * -0.4, y: ScreenSize.height * 0.40)
let backButtonPositionLandscape = CGPoint(x: ScreenSize.width * -0.4, y: ScreenSize.height * -0.20)
func setUpScene() {
if UIDevice.current.orientation == .portrait {
print("I'M IN PORTRAIT RIGHT NOW")
backButton.position = backButtonPositionPortrait
addChild(backButton)
}
if UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight {
print("I'M IN LANDSCAPE RIGHT NOW")
backButton.position = backButtonPositionLandscape
addChild(backButton)
}
}
When the scene first loads the backButton is placed accordingly, on both orientations, but only before entering the scene. When I orientate to the opposite the expected behaviour is that the sprites should move as I placed them, but they seem to only respect the screen dimensions the scene began with and so the sprites end up out of view.
I think I need to look into override func willRotateToInterfaceOrientation and re-invigorate the bounds to recalibrate for the new orientation, but I am not sure what to do about it?