首页 > 图书中心 > Objective-C和Sprite Kit游戏开发从入门到精通

目录

第1章 准备工作 ·····1

1.1 本书内容 ················ 1

1.2 使用Xcode ·············· 2

1.3 第一个Objective-C程序 ·················· 4

1.4 获取帮助 ················ 7

第2章 Objective-C开发基础 ·········8

2.1 代码文件 ················ 9

2.2 注释 ·12

2.3 变量 ·12

2.4 常量 ·13

2.5 整数 ·15

2.5.1 取值范围 ················15

2.5.2 算术运算 ················16

2.5.3 NSLog()函数与格式化输出 ·············17

2.5.4 组合运算符 ·············17

2.5.5 增量与减量运算 ·······18

2.5.6 二进制与位运算 ·······18

2.6 浮点数 ··················23

2.7 布尔类型 ···············24

2.7.1 BOOL类型 ··············24

2.7.2 布尔运算 ················25

2.8 字符 ·26

2.9 指针 ·28

2.10 自定义函数 ··········29

2.10.1 返回值类型 ···········30

2.10.2 函数名 ·················30

2.10.3 参数 30

2.10.4 参数指针 ··············31

2.11 static关键字 ··········32

2.12 块(block) ··········33

2.13 枚举 ···················35

2.14 结构 ···················37

2.15 随机数 ················38

2.16 预处理 ················38

2.16.1 #defi ne和#undef指令 39

2.16.2 条件编译指令 ········39

2.16.3 #import指令 ···········40

第3章 代码流程控制 ················· 41

3.1 比较运算 ···············41

3.2 条件语句 ···············42

3.2.1 if语句 42

3.2.2 ?:运算符 ·················43

3.3 选择语句 ···············44

3.4 循环语句 ···············46

3.4.1 for语句结构 ············46

3.4.2 while语句结构 ·········47

3.4.3 do-while语句结构 ·····47

3.4.4 break语句 ···············48

3.4.5 continue语句 ···········48

3.5 goto语句与标签 ······49

3.6 异常处理 ···············49

第4章 面向对象编程 ················· 51

4.1 面向对象编程基础 ···51

4.2 类与对象 ···············53 

4.2.1 接口部分 ················53 

4.2.2 实现部分 ················54 

4.2.3 创建对象(实例化) ·55 

4.2.4 类的成员 ················56 

4.3 方法(任务) ·········58 

4.3.1 创建方法 ················58 

4.3.2 description方法与NSLog()函数 ·········61 

4.4 属性 ·61 

4.4.1 使用@proeprty和@synthesize指令 ·····62 

4.4.2 使用setter和getter方法 ···················63 

4.5 初始化方法 ············64 

4.6 继承 ·65 

4.6.1 成员的访问 ·············65 

4.6.2 重写属性和方法 ·······67 

4.6.3 继承关系中的初始化 ·67 

4.7 分类 ·69 

4.7.1 命名分类 ················70 

4.7.2 匿名分类 ················71 

4.8 对象复制与传递 ······71 

4.8.1 对象的复制 ·············71 

4.8.2 对象作为参数 ··········72 

4.9 动态处理类和对象 ···72 

4.9.1 对象类型判断 ··········72 

4.9.2 方法存在判断 ··········73 

4.9.3 动态调用方法 ··········74 

第5章协议 ········· 75 

5.1 创建协议 ···············75 

5.2 实现协议 ···············76 

5.3 可选成员 ···············77 

5.4 实现多个协议 ·········78 

5.5 

对象深复制(实现NSCopying 

协议) ··················79 

第6章数组、集合与字典 ··········· 82 

6.1 

C风格数组 ·············82 

6.2 

不可变数组(NSArray类型) ·········84 

6.2.1 创建NSArray对象 ·····84 

6.2.2 数字对象(NSNumber类) ·············84 

6.2.3 使用NSValue 类 ········85 

6.2.4 数组成员操作 ··········86 

6.2.5 保存与载入 ·············87 

6.3 可变数组(NSMutableArray类型)··88 

6.3.1 创建NSMutableArray对象 ···············89 

6.3.2 添加成员 ················89 

6.3.3 删除成员 ················90 

6.3.4 替换成员 ················90 

6.4 集合(Set) ···········91 

6.4.1 不可变集合(NSSet类) ················91 

6.4.2 可变集合(NSMutableSet类) ·········92 

6.5 字典(NSDictionary) ··················93 

6.5.1 创建字典对象 ··········93 

6.5.2 常用成员 ················93 

6.5.3 NSMutableDictionary类 ··················94 

第7章字符串 ······ 96 

7.1 C风格字符串 ··········96 

7.2 不可变字符串(NSString类) ·········97 

7.2.1 创建NSString对象 ·····97 

7.2.2 返回字符数量 ··········98 

7.2.3 截取子字符串和字符 ·98 

7.2.4 大小写转换 ·············99 

7.2.5 转换为C风格字符串 ··99 

7.2.6 字符串比较与匹配 ·· 100 

7.2.7 转换为数值 ··········· 101 

7.2.8 保存与读取 ··········· 101 

7.3 

可变字符串(NSMutableString 

类) ··················· 102 

7.3.1 创建NSMutableString对象············· 102 

7.3.2 NSMutableString常用成员············· 102 

7.4 使用NSURL类 ······ 103 

第8章本地化字符串 ················105 

8.1 判断系统语言类型 · 105 

8.2 NSLocalizedString ·· 106 

8.3 NSLocalizedStringFromTable ········· 107 

8.4 综合应用 ············· 108 

第9章日期与时间 ···················109 

9.1 NSDate类 ············ 109 

9.1.1 获取时间信息 ········ 110 

9.1.2 时间的计算和比较 ·· 110 

9.2 NSDateComponents类 ················· 111 

9.3 NSCalendar类······· 112 

9.4 时区与区域设置 ···· 113 

9.4.1 NSTimeZone 类 ······· 113 

9.4.2 NSDateFormatter类 · 114 

9.4.3 NSLocale类··········· 115 

9.5 封装CDate类········ 115 

9.5.1 初始化方法 ··········· 117 

9.5.2 时间、区域和时区 ·· 118 

9.5.3 日期与时间数据 ····· 119 

9.5.4 测试  120 

9.6 获取中国农历信息 · 120 

9.6.1 初始化方法 ··········· 121 

9.6.2 年份与名称 ··········· 122 

9.6.3 月份与名称 ··········· 123 

9.6.4 日期与名称 ··········· 124 

9.6.5 属相  125 

9.6.6 测试  125 

第10章文件与目录 ·················127 

10.1 获取系统信息 ····· 127 

10.1.1 获取文稿目录(Documents) ······· 128 

10.1.2 获取临时目录与GUID ················ 128 

10.1.3 更多系统信息 ······ 129 

10.2 NSData与NSMutableData类 ········ 130 

10.3 使用NSFileManager类 ··············· 130 

10.3.1 文件或目录是否存在 ················· 131 

10.3.2 复制文件和目录 ··· 131 

10.3.3 删除文件和目录 ··· 132 

10.3.4 移动、重命名文件和目录 ··········· 133 

10.3.5 文件与目录的属性  133 

10.4 文件操作 ··········· 134 

10.4.1 读取文件内容 ······ 134 

10.4.2 写入文件 ············ 134 

10.4.3 比较文件内容 ······ 135 

10.4.4 检测文件读写权限  135 

10.5 目录操作 ··········· 135 

第11章归档 ······137 

11.1 归档与解档 ········ 137 

11.1.1 

实现NSCoding协议  137 

11.1.2 

使用NSKeyedArchiver类和 

NSKeyedUnarchiver类 ··············· 139 

11.2 利用归档复制对象 ··················· 140 

第12章通知中心与对话框 ········142 

12.1 通知中心 ··········· 142 

12.2 OS X对话框········ 146 

12.3 iOS对话框 ·········· 147 

12.3.1 回顾UIAlertView 类  150 

12.3.2 使用UIAlertController类 ·············· 152 

12.3.3 iPad中的UIAlertController ··········· 154 

第13章Sprite Kit基础 ··············156 

13.1 第一个Sprite Kit项目 ················ 156 

13.1.1 启动界面 ············ 159 

13.1.2 视图 ·················· 161 

13.1.3 创建场景 ············ 162 

13.2 iOS设备与系统信息 ·················· 163 

13.2.1 设备类型与iOS版本 ··················· 163 

13.2.2 

屏幕尺寸 ············ 164 

13.2.3 

封装——创建CApp.h和CApp.m 

文件 ·················· 165 

13.3 颜色 ················· 167 

13.4 节点树 ·············· 168 

13.5 Core Graphics······ 171 

13.5.1 CGPoint结构 ········ 171 

13.5.2 CGSize结构 ········· 172 

13.5.3 CGRect结构 ········· 172 

13.5.4 CGRectContainsRect()函数 ·········· 172 

13.5.5 

CGRectContainsPoint()函数 ·········· 172 

13.5.6 

CGRectGetMidX()和CGRectGetMidY()

函数 ········· 173 

13.6 坐标系 ·············· 173 

13.6.1 

位置(position)与锚点

(anchorPoint) ···· 173 

13.6.2 

坐标转换 ············ 174 

13.7 场景切换(SKTransition) ········· 174 

13.8 游戏循环 ··········· 176 

13.9 场景(SKScene)中显示对话框 ·· 178 

13.10 Mac中的Sprite Kit项目 ············· 180 

13.10.1 项目初始化 ········ 180 

13.10.2 响应鼠标与键盘 ·· 181 

13.10.3 屏幕与尺寸 ········ 182 

第14章精灵、纹理与角色控制 ···185 

14.1 SKSpriteNode类 ··· 185 

14.1.1 创建精灵节点 ······ 185 

14.1.2 NSBundle类 ········· 187 

14.1.3 组合节点 ············ 188 

14.2 SKTexture 类 ······· 189 

14.2.1 截取纹理内容 ······ 189 

14.2.2 精灵动画——翻滚的小行星 ········· 191 

14.2.3 更多的小行星 ······ 191 

14.3 移动与碰撞 ········ 192 

14.3.1 场景初始化 ········· 193 

14.3.2 碰撞检测与游戏状态 ················· 197 

14.4 触摸控制 ··········· 200 

14.4.1 触摸响应方法 ······ 200 

14.4.2 控制太空船 ········· 201 

14.4.3 单击 ·················· 202 

14.4.4 手势 ·················· 202 

14.5 Mac中的太空船 ··· 207 

14.5.1 处理鼠标操作 ······ 210 

14.5.2 处理键盘控制 ······ 212 

14.5.3 在update:方法中处理键盘控制 ····· 213 

第15章动作与声音播放 ···········216 

15.1 基本动作类型 ····· 217 

15.1.1 移动 ·················· 217 

15.1.2 尺寸与缩放 ········· 218 

15.1.3 显示和隐藏 ········· 219 

15.1.4 旋转 ·················· 220 

15.1.5 等待 ·················· 221 

15.2 动作的组合 ········ 221 

15.2.1 动作组 ··············· 221 

15.2.2 动作序列 ············ 222 

15.2.3 动作重复 ············ 222 

15.2.4 动画动作 ············ 223 

15.3 声音播放 ··········· 223 

15.3.1 使用动作播放声音  223 

15.3.2 使用AVAudioPlayer 播放声音 ········ 224 

15.4 动作的使用 ········ 224 

15.4.1 执行动作 ············ 225 

15.4.2 通过键(Key)执行动作 ············ 225 

15.4.3 取消所有动作 ······ 226 

15.4.4 判断节点是否有动作执行 ··········· 226 

15.4.5 修改动作速度 ······ 226 

第16章更多节点类型 ··············227 

16.1 SKShapeNode ······ 228 

16.1.1 基本图形节点 ······ 229 

16.1.2 根据路径创建图形节点 ·············· 230 

16.2 SKVideoNode ······ 231 

16.3 SKCropNode ······· 232 

16.4 SKEffectNode ······ 233 

16.5 SKEmitterNode与粒子效果 ········· 234 

16.5.1 在Xcode中创建粒子 ·················· 234 

16.5.2 下雪场景 ············ 235 

16.5.3 模拟爆炸 ············ 236 

16.5.4 SKEmitterNode 类 · 238 

16.6 节点的组合 ········ 240 

第17章Sprite Kit游戏常用算法 ···242 

17.1 两点距离 ··········· 242 

17.2 碰撞测试 ··········· 243 

17.3 角度 ················· 245 

17.4 视线 ················· 246 

17.5 躲避障碍物 ········ 249 

第18章综合测试——Mac版

坦克大战 251 

18.1 场景初始化 ········ 252 

18.1.1 创建坦克 ············ 254 

18.1.2 创建敌人 ············ 254 

18.1.3 创建岩石 ············ 255 

18.2 坦克的操作 ········ 255 

18.2.1 坦克的动作 ········· 256 

18.2.2 鼠标和键盘控制 ··· 257 

18.2.3 自动执行 ············ 258 

18.3 敌人的AI ··········· 259 

18.4 处理已发射炮弹 ·· 261 

18.5 自己动手 ··········· 262 

第19章加速计与陀螺仪 ···········263 

19.1 自动响应 ··········· 264 

19.2 调用数据 ··········· 267 

19.3 游戏控制方法小结 ··················· 269 

19.3.1 触摸屏 ··············· 269 

19.3.2 键盘与鼠标 ········· 270 

第20章网络状态 271 

20.1 检测网络状态 ····· 271 

20.2 监视网络状态 ····· 272 

第21章Game Center排行榜 ·····274 

21.1 配置排行榜 ········ 274 

21.2 在应用中处理排行榜 ················ 275 

21.2.1 Game Center登录状态 ················ 275 

21.2.2 提交成绩 ············277

第22章 应用内购买 ·················280

22.1 准备测试用户和设备 ················280

22.2 创建App内购买 ···281

22.3 在项目中使用App内购买 ···········282

22.3.1 检测访问限制与网络 ·················282

22.3.2 执行购买操作 ······285

22.3.3 恢复已购项目 ······287

22.3.4 在场景(SKScene)中执行购买操作 ···287

22.3.5 在场景(SKScene)中执行恢复操作 ··290

第23章 发布到App Store ··········292

23.1 注册开发者与设备 ···················292

23.2 发布准备 ···········293

23.2.1 应用图标 ············293

23.2.2 iOS应用截图 ········294

23.2.3 OSX应用截图 ······295

23.2.4 上传应用 ············295

23.2.5 项目审核 ············295

版权所有(C)2019 清华大学出版社有限公司 京ICP备10035462号 京公网安备11010802013248号

联系我们 | 网站地图 | 法律声明 | 友情链接 | 盗版举报 | 人才招聘