I'm trying to show a scene on an external display (iOS). I made a simple program using what I have found regarding this topic, but it doesn't work. I suspect that I'm just missing a setting or two.
I started with the simple 'Hello, World' example game that XCode makes for an iOS SpriteKit project. I modified the GameViewController class to the following:
class GameViewController: UIViewController {
var primaryView: SKView?
var secondaryView: SKView?
override func viewDidLoad() {
super.viewDidLoad()
checkForExternalDisplay()
if let view = primaryView {
if let scene = SKScene(fileNamed: "GameScene") {
scene.scaleMode = .aspectFill
view.presentScene(scene)
}
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
}
}Here is the code for 'checkForExternalDisplay':
func checkForExternalDisplay() {
let screens = UIScreen.screens
if screens.count > 1 {
let mainScreenIndex = self.view.frame.width == screens[0].bounds.width ? 0 : 1
let otherScreenIndex = self.view.frame.width == screens[0].bounds.width ? 1 : 0
let primaryScreenIndex = screens[0].bounds.width > screens[1].bounds.width ? 0 : 1
let otherWindow = UIWindow(frame: screens[otherScreenIndex].bounds)
otherWindow.rootViewController = UIViewController()
otherWindow.screen = screens[otherScreenIndex]
let otherView = UIView(frame: screens[otherScreenIndex].bounds)
otherWindow.addSubview(otherView)
otherWindow.isHidden = false
otherWindow.makeKeyAndVisible()
if primaryScreenIndex == mainScreenIndex {
primaryView = self.view as? SKView
} else {
primaryView = otherView as? SKView
}
} else {
primaryView = self.view as? SKView
}
primaryView?.backgroundColor = SKColor.green
}When I run the program with just the iOS display (in the simulator), it works fine. However, when I add an external display in the simulator, and then launch the app, the scene doesn't show in either of the windows (I want it to show in the external window).
Any advice? Did I miss something, or do I have something set incorrectly?