I had scene set up and everything worked well. It looked like this:
But the controller was set up in Main.storyboard and I wanted to get rid of it. So I did something like this:
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = GameViewController()
in appDelegate and this:
override func loadView() {
super.loadView()
self.view = SKView()
}
in GameViewController to load it. First time, the scene loaded, but only the green background, no other nodes. (Node counter showed the correct number of nodes.)
So I tried setting the ignoresSiblingOrder both true and false, all options of scene.scaleMode and the best result that I achieved was with scene.scaleMode = .resizeFill. Looked like this:
EDIT: Position for circles:
greenOne.position = CGPoint(x: greenOne.radius + sticksOffset, y: greenOne.radius + sticksOffset)
redOne.position = CGPoint(x: self.frame.maxX - redOne.radius - sticksOffset / 2, y: view.bounds.size.height / 2)
Tried this and redOne appeared next to the green
redOne.position = CGPoint(x: redOne.radius + 100, y: 200)
It seems that the view didn't fit the screen and is just too large.
Solved by changing view init in GameViewController:
override func loadView() {
super.loadView()
self.view = SKView(frame: UIScreen.main.applicationFrame)
}
The old version of view had zero width and height, so the GameScene didn't get any dimensions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.