官术网_书友最值得收藏!

Sharpening our pencils

There are four quick items to take care of before we start drawing:

  1. Since we will design our game to use landscape screen orientations, we will disable the portrait view altogether:
    1. With your game project open in Xcode, select the overall project folder in the project navigator (the top-most item).
    2. You will see your project settings in the main frame of Xcode. Under Deployment Info, find the Device Orientation section.
    3. Uncheck the Portrait option, as shown in the following screenshot:
  2. The SpriteKit template generates a visual layout file for arranging sprites in our scene. We will not need it; we will use the SpriteKit visual editor later when we explore level design. To delete this extra file:
    1. Right-click on GameScene.sks in the project navigator and choose delete.
    2. Choose Move to Trash in the dialog window.
  3. We need to resize our scene to fit the new landscape view. Follow these steps to resize the scene:
    1. Open GameViewController.swift from the project navigator and locate the viewDidLoad function inside the GameViewController class. The viewDidLoad function is going to fire before the game realizes it is in landscape view, so we need to use a function that fires later in the startup process. Delete viewDidLoad completely, removing all of its code.
    2. Replace viewDidLoad with a new function named viewWillLayoutSubviews. Do not worry about understanding every line right now; we are just configuring our project. Use this code for viewWillLayoutSubviews:
      override func viewWillLayoutSubviews() {
          super.viewWillLayoutSubviews()
          // Create our scene:
          let scene = GameScene()
          // Configure the view:
          let skView = self.view as! SKView
          skView.showsFPS = true
          skView.showsNodeCount = true
          skView.ignoresSiblingOrder = true
          scene.scaleMode = .AspectFill
          // size our scene to fit the view exactly:
          scene.size = view.bounds.size
          // Show the new scene:
          skView.presentScene(scene)
      }
    3. Lastly, in GameViewController.swift, find the supportedInterfaceOrientations function and reduce it to this code:
      override func supportedInterfaceOrientations() -> Int {
          return Int(
          UIInterfaceOrientationMask.Landscape.rawValue);
      }
      Tip

      Downloading the example code

      You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

      Additionally, each chapter provides checkpoint links you can use to download the example project to that point.

  4. We should double-check that we are ready to move on. Try to run our clean project in the simulator using the toolbar play button or the command + r keyboard shortcut. After loading, the simulator should switch to landscape view with a blank gray background (and with the node and FPS counter in the bottom right). If the project will not run, or you still see "Hello World", you will need to retrace your steps from the end of Chapter 1, Designing Games with Swift, to finish your project preparation.
主站蜘蛛池模板: 和田市| 青铜峡市| 凌源市| 建宁县| 永胜县| 大余县| 观塘区| 广平县| 乌拉特中旗| 兴安县| 定州市| 顺昌县| 宁波市| 赤水市| 太白县| 福海县| 兴海县| 高陵县| 道孚县| 永修县| 醴陵市| 新蔡县| 公安县| 河津市| 泸西县| 汝州市| 栾城县| 沐川县| 淳安县| 离岛区| 梁山县| 石楼县| 焦作市| 长阳| 维西| 潼关县| 盐津县| 信丰县| 旬阳县| 溧水县| 河源市|