Real-machine testing of the IOS Sprite Kit tutorial and the addition and presentation of scenes

Source: Internet
Author: User
<span id="Label3"></p>iOS Sprite Kit Tutorial Real-machine test and scene add and show iOS implement Real-machine test<p><p>Before you perform a real-machine test, you first need to make sure that your device is connected to your Mac (or mac virtual machine) and that the device is connected to your Mac (or mac virtual machine) at the start of section 1.9.1, and that the device is Registered. Open the created project, and in the Run button column, set the device that the program is running to the name of the real Machine. It is automatically loaded into the "choose device to run by program" item, as shown in 1.102. Click the Run button to see that the application is running on the real machine.</p></p><p class="a"><p class="a"></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong></strong></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong>Figure 1.102 Setting up the device</strong></p></p>The scene of the Sprite kit<p><p>When a player enters a game on a mobile device or on a computer, the content that appears on the screen is called a scene, as shown in 2.1. In the game, the scene is a level, or a game interface. Such a scene makes up a game. This chapter explains how to add, display, set, toggle, and scroll the SCENE.</p></p><p class="a" style="text-align: center;"><p class="a" style="text-align: center;"></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong>Figure 2.1 Field View</strong></p></p>Sprite Kit Add scene<p><p>In a game, one or more scenes may be composed, depending on the design requirements of the game to Decide. So how is the scene added? This is the problem that will be addressed in this Section. The steps to add a new scene are as Follows:</p></p><p><p><strong>(1</strong> <strong></strong> Click Xcode to bring up the Welcome to Xcode Dialog box. Select the Create a new Xcode project option, which pops up choose a template for your new Project: dialog box, shown in 2.2.</p></p><p class="a"><p class="a"></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong></strong></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong>Figure 2.2 Creating a project</strong> <strong>1</strong></p></p><p><p><strong>(2</strong> <strong>)</strong> Select ios| Application in the game template, after clicking the next button, pop up choose options for your new Project: dialog box, shown in 2.3.</p></p><p class="a"><p class="a"></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong></strong></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong>Figure 2.3 Creating a project</strong> <strong>2</strong></p></p><p><p><strong>(3</strong> <strong></strong> fill in the product name (project name), Organization Identifier (identifier) information, and select language (programming language) and device devices (device), as shown in table 2-1.</p></p><p class="a4" style="text-align: center;"><p class="a4" style="text-align: center;"><strong>Table 2-1 What to fill out</strong></p></p><p><p><strong>(4</strong> <strong></strong> Click the Next button to pop up the save Location dialog frame and click the Create Button. At this point, a project named 2-1 is Created.</p></p><p><p><strong>(5</strong> <strong></strong> Click the project name, open the target window, Select the general option, and open the general panel. Locate the device orientation option in which you select the landscape left and landscape right radio Boxes. Let the running emulator direction change to landscape, as shown in 2.4.</p></p><p class="a"><p class="a"></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong></strong></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong>Figure 2.4 Modifying the orientation of the device</strong></p></p><p><p><strong>(6</strong> <strong>)</strong> Select file| on the menu bar new| The file command, shown in 2.5.</p></p><p class="a"><p class="a"></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong></strong></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong>Figure 2.5 Adding a new scene</strong> <strong>1</strong></p></p><p><p><strong>(7</strong> <strong>)</strong> pops up choose a template for your new File: dialog box, shown in 2.6.</p></p><p class="a"><p class="a"></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong></strong></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong>Figure 2.6 Adding a new scene</strong> <strong>2</strong></p></p><p><p><strong>(8</strong> <strong>)</strong> Select ios| source| For the Swift file template, Click the next button, which pops up a dialog box that sets up the files information, including the file name and location, as shown in 2.7.</p></p><p class="a"><p class="a"></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong></strong></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong>Figure 2.7 Adding a new scene</strong> <strong>3</strong></p></p><p><p><strong>(9</strong> <strong></strong> After entering the file name, Click the Create button and create a new Newgamescene.swift file in the project you Created. Click Open Newgamescene.swift file to create an empty class with the following code:</p></p><p class="a1"><p class="a1"></p></p> <ul> <ul> <li>Import SpriteKit</li> <li>The creation of a class</li> <li><strong>Class Newgamescene:skscene {</strong></li> <li><strong></strong></li> <li><strong>}</strong></li> </ul> </ul><p><p></p></p><p><p>At this point a new scene is Added.</p></p>The new scene is displayed in the Sprite kit<p><p>In section 2.1, when you add a new scene, the new scene is not displayed on the Device's screen, so how do you display the new scene in the screen? This is what is going to be explained in this Section.</p></p><p class="4"><p class="4"><strong>1. Create a scene</strong></p></p><p><p>Creating a scene is also called instantiating an object. Since each scenario is based on the Skscene class, each scenario has a common method of instantiating the object, which has the following syntax:</p></p><p class="a1"><p class="a1"></p></p> <ul> <ul> <li>Init (size Size:cgsize)</li> </ul> </ul><p><p></p></p><p><p>Where size is the size of the scene Object.</p></p><p class="4"><p class="4"><strong>2. Display the scene</strong></p></p><p><p>When you create a scene, you run the program at this point, and the newly added scene cannot be Displayed. If you want to display a new scene, you need to use Presentscene (_ scene:skscene?). method, which is used to display a scene with the following syntax:</p></p><p class="a1"><p class="a1"></p></p> <ul> <ul> <li>Func presentscene (_ scene:skscene?)</li> </ul> </ul><p><p></p></p><p><p>Where _ scene is used to represent the scene that needs to be displayed.</p></p><p><p>"example 2-1" below will be based on project 2-1 and the new scene added will be displayed on the screen with the following steps:</p></p><p><p>Open the Gameviewcontroller.swift file and delete some of the code in the Gameviewcontroller.swift file. At this point the remaining code is as Follows:</p></p><p class="a1"><p class="a1"></p></p> <ul> <ul> <li>Import UIKit</li> <li>Import SpriteKit</li> <li>Class Gameviewcontroller:uiviewcontroller {</li> <li>Override Func Viewdidload () {</li> <li>Super.viewdidload ()</li> <li>}</li> <li></li> <li>}</li> </ul> </ul><p><p></p></p><p><p>Add the following code to the Viewdidload () method, and this code implements the ability to display the newly added scene on the screen:</p></p><p class="a1"><p class="a1"></p></p> <ul> <li><li>Override Func Viewdidload () {</li></li> <li><li>Super.viewdidload ()</li></li> <li><li>Let Skview = Self.view as Skview</li></li> <li><li>Determines whether the scene property of the Skview is empty</li></li> <li><li>if (skview.scene = = Nil) {</li></li> <li><li>Skview.showsfps=true</li></li> <li><li>Skview.showsnodecount=true</li></li> <li><li>let <strong>scene=newgamescene (size:skView.bounds.size) </strong>//create scene</li></li> <li><li><strong>Skview.presentscene (scene) </strong>//show Scene</li></li> <li><li>}</li></li> <li><li>}</li></li> </ul><p><p></p></p><p><p>When you run the program, you see the effect shown in 2.8.</p></p><p class="a"><p class="a"></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong></strong></p></p><p class="a0" style="text-align: center;"><p class="a0" style="text-align: center;"><strong>Figure 2.8 Running effect</strong></p></p><p class="a2"><p class="a2"><strong>note:</strong> The Skview class is a view that is designed to present the sprite Kit. In this class, you can render and manage a skscene. You can load multiple sprites in each scene and manage their behavior.</p></p><p class="a2"><p class="a2"><strong>This article is selected from:</strong>iOS game frame Sprite Kit Basic Tutorial--swift version of the University PA Internal information, reproduced Please indicate the source, respect the technology respect the IT person!</p></p><p><p>Real-machine testing of the IOS Sprite Kit tutorial and the addition and presentation of scenes</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.