April 2021
Beginner to intermediate
506 pages
11h 57m
English
In Setting the Camera’s Viewport, you learned about the camera’s viewport and how certain camera settings, like its position and scale, have an inverse effect on how the scene renders. Armed with that information, you can solve the problem of the resizing player.
Still inside the GameScene.swift file, add the following code to the didChangeLayout() method:
| | let w = view?.bounds.size.width ?? 1024 |
| | let h = view?.bounds.size.height ?? 1336 |
| | |
| | if h >= w { // portrait, which matches the design |
| | camera?.setScale(1.0) |
| | } else { |
| | camera?.setScale(1.25) // helps to keep relative size |
| | // larger numbers results in "smaller" scenes |
| | } |
This code first checks the height and width of the view ...
Read now
Unlock full access