vi
目录
1.19
二维网格
................................................................................................... 39
1.20
使用随机数
............................................................................................... 40
1.21
编写状态机
............................................................................................... 42
2
视图和菜单
....................................................46
2.1
使用故事板
................................................................................................ 47
2.2
创建视图控制器
......................................................................................... 53
2.3
通过
Segue
导航到不同屏幕
...................................................................... 60
2.4
使用布局约束进行布局
.............................................................................. 65
2.5
导入图片到项目
........................................................................................ 68
2.6
切割按钮的背景图片
................................................................................. 70
2.7
UIDynamics
创建动画视图
................................................................... 71
2.8
Core Animation
移动图片
....................................................................... 74
2.9
旋转图片
.................................................................................................... 75
2.10
实现视图的弹起效果
............................................................................... 77
2.11
UIAppearance
主题化
UI
样式
............................................................ 79
2.12
UIView
进行
3D
旋转
.......................................................................... 80
2.13
在游戏内容之上显示菜单
........................................................................ 83
2.14
创建高效的游戏菜单
............................................................................... 84
3
输入
.............................................................86
3.1
侦测触摸
.................................................................................................... 87
3.2
处理轻触手势
............................................................................................ 88
3.3
在屏幕上拖动图片
...................................................................................... 90
3.4
识别旋转手势
............................................................................................ 92
3.5
识别捏合手势
............................................................................................. 94
3.6
自定义手势
................................................................................................ 96
3.7
在视图的指定区域识别触摸
.................................................................... 100
3.8
识别摇晃手势
.......................................................................................... 101
3.9
识别设备倾斜手势
................................................................................... 102
3.10
获得指北针方向
..................................................................................... 106
3.11
获得用户的位置
..................................................................................... 108
目录
vii
3.12
计算运动速度
........................................................................................ 112
3.13
计算用户与目标的距离
......................................................................... 113
3.14
当用户进入或离开某个位置时获得通知
............................................... 114
3.15
通过地名获得坐标
.................................................................................. 118
3.16
通过坐标获得地名
................................................................................. 119
3.17
将设备当作方向盘
................................................................................. 121
3.18
测量磁场
................................................................................................ 122
3.19
利用输入改善游戏设计
......................................................................... 124
4
声音
........................................................... 126
4.1
AVAudioPlayer
播放声音
.................................................................... 126
4.2
AVAudioRecorder
进行录音
................................................................. 130
4.3
使用多个
AVAudioPlayer .......................................................................... 131
4.4
两个声音间的淡入淡出
........................................................................... 133
4.5
合成语音
.................................................................................................. 136
4.6
获知音乐程序当前播放曲目
.................................................................... 137
4.7
当前曲目何时改变
................................................................................... 140
4.8
音乐回放控制
.......................................................................................... 141
4.9
让用户选择音乐
....................................................................................... 142
4.10
当其他
App
正在播放音乐时的操作
....................................................... 145
4.11
在游戏中使用哪种声音播放模式最好
.................................................... 147
5
存储数据
...................................................... 148
5.1
保存游戏状态
.......................................................................................... 148
5.2
在本地保存游戏得分
................................................................................ 150
5.3
iCloud
保存游戏进度
.......................................................................... 151
5.4
使用
iCloud
的键
值存储
....................................................................... 157
5.5
何时使用文件
何时使用数据库
............................................................ 159
5.6
管理资源集
.............................................................................................. 160
5.7
NSUserDefaults
存放数据
.................................................................... 162
5.8
最佳数据存储策略
................................................................................... 164
5.9
游戏中的财富值
...................................................................................... 165
viii
目录
5.10
保存到
CloudKit ..................................................................................... 166
5.11
CloudKit
数据库中添加记录
.............................................................. 168
5.12
查询
CloudKit
数据库中的记录
.............................................................. 169
5.13
CloudKit
数据库中删除记录
.............................................................. 173
6
2D
图形和
Sprite Kit .................................... 175
6.1
熟悉二维数学
........................................................................................... 176
6.2
创建
Sprite Kit
视图
................................................................................. 183
6.3
创建场景
.................................................................................................. 184
6.4
加入精灵
................................................................................................... 187
6.5
文本精灵
.................................................................................................. 188
6.6
获取有效字体
........................................................................................... 190
6.7
使用自定义字体
...................................................................................... 191
6.8
场景切换
................................................................................................... 191
6.9
移动精灵和标签
....................................................................................... 194
6.10
纹理贴图精灵
........................................................................................ 197
6.11
纹理图集
................................................................................................ 197
6.12
形状节点
................................................................................................ 198
6.13
混合模式
................................................................................................ 200
6.14
对精灵使用滤镜
...................................................................................... 201
6.15
贝塞尔曲线
............................................................................................. 202
6.16
烟雾
火焰和粒子特效
......................................................................... 204
6.17
抖动屏幕
................................................................................................ 205
6.18
动画精灵
................................................................................................ 207
6.19
视差滚动
................................................................................................ 208
6.20
噪声图
................................................................................................... 215
7
物理学
........................................................217
7.1
物理学术语和定义
................................................................................... 217
7.2
为精灵添加物理特性
................................................................................ 219
7.3
静止物体和运动物体
................................................................................ 220
7.4
定义碰撞体的形状
................................................................................... 221
目录
ix
7.5
速度
......................................................................................................... 224
7.6
质量
大小和密度
................................................................................... 224
7.7
创建墙壁
.................................................................................................. 226
7.8
设置重力
.................................................................................................. 227
7.9
让物体无法旋转
...................................................................................... 229
7.10
改变物理模拟世界的时钟
....................................................................... 229
7.11
碰撞检测
................................................................................................ 230
7.12
查找物体
................................................................................................ 231
7.13
连接
....................................................................................................... 233
7.14
作用力
.................................................................................................... 235
7.15
在物体上添加推进器
............................................................................. 236
7.16
制造爆炸
................................................................................................ 237
7.17
根据设备方向改变重力
......................................................................... 239
7.18
拖动物体
................................................................................................ 241
7.19
创建车辆
................................................................................................ 243
8
Scene Kit .................................................... 246
8.1
使用
Scene Kit ......................................................................................... 246
8.2
创建一个
Scene Kit
场景
......................................................................... 247
8.3
显示
3D
对象
........................................................................................... 248
8.4 Scene Kit
的镜头
..................................................................................... 248
8.5
创建灯光
.................................................................................................. 249
8.6
移动
......................................................................................................... 251
8.7
使用文本节点
.......................................................................................... 252
8.8
自定义材质
.............................................................................................. 252
8.9
纹理对象
.................................................................................................. 254
8.10
法向贴图
................................................................................................ 254
8.11
约束对象
................................................................................................ 255
8.12
加载
3D
模型文件
.................................................................................. 256
8.13 3D
物理学
.............................................................................................. 257
8.14
反射
....................................................................................................... 258
8.15
点击测试
................................................................................................ 259
x
目录
8.16
加载场景文件
......................................................................................... 260
8.17
粒子系统
................................................................................................. 260
8.18 Metal ....................................................................................................... 261
9
人工智能和行为
.......................................... 263
9.1 Swift
使向量计算更轻松
........................................................................... 263
9.2
让对象朝某个点移动
............................................................................... 266
9.3
跟随路径
.................................................................................................. 268
9.4
拦截运动物体
.......................................................................................... 269
9.5
逃逸
......................................................................................................... 270
9.6
目标选择问题
.......................................................................................... 271
9.7
转向问题
................................................................................................... 272
9.8
隐蔽点问题
.............................................................................................. 273
9.9
路径算法
................................................................................................... 274
9.10
网格中的路径查找
.................................................................................. 279
9.11
计算下一步问题
..................................................................................... 280
9.12
判断对象能否
看见
其他对象
.......................................................... 281
9.13
NSLinguisticTagger
作词性标注
........................................................ 283
9.14
AVFoundation
框架访问相机
............................................................. 285
9.15
导入
Core ML
模型
................................................................................. 288
9.16
识别图片中的物体
.................................................................................. 289
9.17
用人工智能增强游戏设计
...................................................................... 293
10
使用外设
................................................... 294
10.1
检测控制器
............................................................................................ 296
10.2
从游戏控制器中获得输入
...................................................................... 298
10.3
通过
AirPlay
显示游戏内容
.................................................................... 300
10.4
使用扩展屏幕
........................................................................................ 301
10.5
为不同的屏幕适配
UI ............................................................................ 303
10.6
拖放
....................................................................................................... 307
10.7
UIFeedbackGenerator
实现触觉回馈
.................................................. 313
10.8
ReplayKit
记录屏幕
........................................................................... 315

Get Swift游戏开发经典实例 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.