
2.1 添加场景
在一个游戏中,可能由一个或者多个场景组成,具体需要根据游戏的设计要求来决定。那么场景是如何进行添加的呢?这就是本节将要解决的问题。添加一个新的场景的具体步骤如下:
(1)单击Xcode,弹出Welcome to Xcode对话框。选择Create a new Xcode project选项,弹出Choose a template for your new project:对话框,如图2.2所示。

图2.2 Choose a template for your new project:对话框
(2)选择iOS|Application中的Game模板,单击Next按钮后,弹出Choose options for your new project:对话框,如图2.3所示。

图2.3 Choose options for your new project:对话框
(3)填入Product Name(项目名)、Organization Identifier(标识符)信息以及选择Language(编程语言)和设备Devices(设备),如表2-1所示。
表2-1 填写的内容

(4)单击Next按钮,弹出保存位置对话框,单击Create按钮。此时,一个名为2-1的项目就创建好了。
(5)单击项目名称,打开目标窗口,选择General选项,打开General面板。在其中找到Device Orientation选项,选中Landscape Left和Landscape Right复选框。让运行的模拟器方向变为横向,如图2.4所示。

图2.4 修改设备的方向
(6)选择菜单栏上的File|New|File命令,如图2.5所示。

图2.5 添加新场景
(7)弹出Choose a template for your new file:对话框,如图2.6所示。

图2.6 Choose a template for your new file:对话框
(8)选择iOS|Source|Swift file模板,单击Next按钮,弹出设置文件信息的对话框,其中包括文件名称和位置,如图2.7所示。

图2.7 设置文件信息
(9)输入文件名称后,单击Create按钮,此时就在创建的项目中新建了一个NewGameScene.swift的文件。单击打开NewGameScene.swift文件,创建一个空的类,代码如下:
import SpriteKit
//类的创建
class NewGameScene: SKScene {
}
此时一个新的场景就被添加好了。