Set the Supported Device Orientation

The default iOS Game template is set to work in both portrait and landscape orientation. However, Gloop Drop is designed for landscape only, so you need to restrict the device orientation.

In the Project Navigator, select the gloopdrop project and look at the Deployment Info section in the Project Editor. You need to set a few options in this section.

First, verify that the iPhone and iPad devices are both enabled. Gloop Drop is also designed to work universally, so you need to let the compiler know to target both.

Next, disable the Portrait option and enable Requires full screen as shown in the following image:

images/CreatingScenesWithSpritesAndNodes/spritekit-deployment-info.png

You might think that disabling the Portrait option in this section is enough to force landscape orientation on all devices, but it’s not. To fix this problem, you need to temporarily disable the iPhone option while you set up the iPad options separately, like so:

images/CreatingScenesWithSpritesAndNodes/spritekit-ipad-options.png
images/aside-icons/important.png

Once you have everything set up, don’t forget to re-enable iPhone support.

When you make the changes here, you’re asking Xcode to reach into the Info.plist file and automatically update this file on your behalf. The information property list[19] file stores information about your project. To verify that the supported orientations are set up correctly, select the Info.plist file from the Project Navigator, and you’ll see the following options near the bottom:

images/CreatingScenesWithSpritesAndNodes/spritekit-info-plist.png

If your settings match what you see here, then your setup is correct—but hang on, you’re not done yet. There’s still one more thing you need to do.

In the GameViewController.swift file, modify the supportedInterfaceOrientations property from this:

 override​ ​var​ supportedInterfaceOrientations: ​UIInterfaceOrientationMask​ {
 if​ ​UIDevice​.current.userInterfaceIdiom == .phone {
 return​ .allButUpsideDown
  } ​else​ {
 return​ .all
  }
 }

to this:

 override​ ​var​ supportedInterfaceOrientations: ​UIInterfaceOrientationMask​ {
 return​ .landscape
 }

The supportedInterfaceOrientations is an instance property that returns all of the interface orientations this view controller supports. Since this game supports only landscape, it makes sense to return only .landscape.

Build and run the project. If everything works as expected, you’ll see a gray screen like the image.

images/CreatingScenesWithSpritesAndNodes/spritekit-build-01.png

(To rotate the device, select Hardware Rotate Right from the Simulator app menu until its orientation is set to landscape.)

At this point, you’re ready to build your first scene.

Xcode 12 and Universal Screen-Size Support

images/aside-icons/important.png

At the time of this writing, it looks as if some key settings that enable universal support are not set when using Xcode 12. If you’re using Xcode 12, you’ll need to add a plist entry for Launch screen interface file base name. You can either add this entry and set its value to Main or create a custom LaunchScreen.storyboard file and set its value to LaunchScreen instead.

Alternatively, you can set this option using the drop-down list in the App Icons and Launch Images section of the General tab of the target settings. Either way, you must use an Xcode storyboard to provide a launch screen if you intend to accommodate different screen sizes. Xcode 11 automatically sets this option for you.

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.172.82