0

My goal is to build and run the Xcode SpriteKit Template Project on an iPhone 12 Pro Max. I will be using Xcode Version 12.5 (12E262). I have made plenty of projects in the past, but recently, when the app launches the frame of the view is incorrect.

I'll show you what I mean through a repeatable example.
Follow these steps very carefully:

  1. Open your Xcode App
  2. In the Menu select: File > New > Project...
  3. Select the templet: iOS, Game
  4. Click "Next"
  5. Name your product "Foo" or some other simple name
  6. Click "Next"
  7. Click "Create"
  8. In the Menu select: Product > Destination > iPhone 12 Pro Max
  9. In the Menu select: Product > Run
  10. Now, wait for your Simulator to launch and voila...
  11. In the Menu select: View > Enter Full Screen

If you followed the steps carefully this is what you should get

For those of you who are unable to view the image:
I have taken a screenshot of the Simulated iPhone after it launched. Since we are running the SpriteKit template project, the simulator is displaying a grey background with the text "Hello World" in the center, per usual. Upon further inspection, the dimensions of the grey background don't seem to fit the iPhone in the most optimal way. In fact, the grey background ratio is (1.5:1) wheras the iPhone 12 Pro Max ratio is approximately (2.16:1), a large difference. This is resulting in large black rectangles above and below the view. Well that's annoying!


Inside the file GameViewController.swift, within the viewDidLoad() method on line 22 I added:

print(view.frame.size, scene.size) // prints (320.0, 480.0) (750.0, 1334.0)

I noted that:

  • view.frame.size has an incorrect ratio: 480 : 320 = (1.5:1)
  • scene.size has more correct ratio of: 1334 : 750 ~ (1.78:1)

It seems like I have discovered the culprit, but I have no idea how to fix it.

0-1
  • 702
  • 1
  • 10
  • 30

1 Answers1

0

I just found a solution based upon Background is not filling the whole view Spritekit

Apparently, you have to add a Launch Screen.
There are 2 ways to accomplish this:

Option 1

In the Info.plist, add the Launch screen interface file base name tag, and type "Main" as it's value.

Option 2

Go to General > App Icons and Launch Images. You'll notice that "Launch Screen File" is empty. Just type in "Main"

0-1
  • 702
  • 1
  • 10
  • 30