Objective-C和Sprite Kit遊戲開發從入門到精通

Objective-C和Sprite Kit遊戲開發從入門到精通

《Objective-C和Sprite Kit遊戲開發從入門到精通》是於2017年1月清華大學出版社出版的一本圖書,作者是曹化

前言,圖書簡介,目錄,

前言

為什麼要寫這本書這是一個真實的故事。兒時與兄弟們玩街機和FC遊戲的場景仍歷歷在目,不知不覺中就玩到了20世紀90年代。在學習和使用計算機過程中,發現除了能敲出自己的名字,還可以玩一些那么有吸引力的遊戲——海闊開空、千軍萬馬,數不清的戰鬥!數不清的不眠之夜!玩果然是天性!

圖書簡介

本書是一執行緒序員凝聚自己多年開發經驗的結晶之作,深入淺出地講解Objective-C語言、
Foundation框架、SpriteKit框架,以及其他開發iOS和Mac遊戲所需要的基礎知識,幫助讀者零基礎實踐
iOS和Mac遊戲開發。

目錄

第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.3NSLog()函式與格式化輸出·············17
2.5.4組合運算符·············17
2.5.5增量與減量運算·······18
2.5.6二進制與位運算·······18
2.6浮點數··················23
2.7布爾類型···············24
2.7.1BOOL類型··············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.11static關鍵字··········32
2.12塊(block)··········33
2.13枚舉···················35
2.14結構···················37
2.15隨機數················38
2.16預處理················38
2.16.1#define和#undef指令39
2.16.2條件編譯指令········39
2.16.3#import指令···········40
第3章代碼流程控制·················41
3.1比較運算···············41
3.2條件語句···············42
3.2.1if語句42
3.2.2?:運算符·················43
3.3選擇語句···············44
3.4循環語句···············46
3.4.1for語句結構············46
3.4.2while語句結構·········47
3.4.3do-while語句結構·····47
3.4.4break語句···············48
3.4.5continue語句···········48
3.5goto語句與標籤······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.2description方法與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.1C風格數組·············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.3NSMutableDictionary類··················94
第7章字元串······96
7.1C風格字元串··········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.2NSMutableString常用成員·············102
7.4使用NSURL類······103
第8章本地化字元串················105
8.1判斷系統語言類型·105
8.2NSLocalizedString··106
8.3NSLocalizedStringFromTable·········107
8.4綜合套用·············108
第9章日期與時間···················109
9.1NSDate類············109
9.1.1獲取時間信息········110
9.1.2時間的計算和比較··110
9.2NSDateComponents類·················111
9.3NSCalendar類·······112
9.4時區與區域設定····113
9.4.1NSTimeZone類·······113
9.4.2NSDateFormatter類·114
9.4.3NSLocale類···········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.2NSData與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.2OSX對話框········146
12.3iOS對話框··········147
12.3.1回顧UIAlertView類150
12.3.2使用UIAlertController類··············152
12.3.3iPad中的UIAlertController···········154
第13章SpriteKit基礎··············156
13.1第一個SpriteKit項目················156
13.1.1啟動界面············159
13.1.2視圖··················161
13.1.3創建場景············162
13.2iOS設備與系統信息··················163
13.2.1設備類型與iOS版本···················163
13.2.2螢幕尺寸············164
13.3顏色·················167
13.4節點樹··············168
13.6.2坐標轉換············174
13.7場景切換(SKTransition)·········174
13.8遊戲循環···········176
13.9場景(SKScene)中顯示對話框··178
13.10Mac中的SpriteKit項目·············180
13.10.1項目初始化········180
13.10.2回響滑鼠與鍵盤··181
13.10.3螢幕與尺寸········182
第14章精靈、紋理與角色控制···185
14.1SKSpriteNode類···185
14.1.1創建精靈節點······185
14.1.2NSBundle類·········187
14.1.3組合節點············188
14.2SKTexture類·······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.5Mac中的太空船···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.1SKShapeNode······228
16.1.1基本圖形節點······229
16.1.2根據路徑創建圖形節點··············230
16.2SKVideoNode······231
16.3SKCropNode·······232
16.4SKEffectNode······233
16.5SKEmitterNode與粒子效果·········234
16.5.1在Xcode中創建粒子··················234
16.5.2下雪場景············235
16.5.3模擬爆炸············236
16.5.4SKEmitterNode類·238
16.6節點的組合········240
第17章SpriteKit遊戲常用算法···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章GameCenter排行榜·····274
21.1配置排行榜········274
21.2在套用中處理排行榜················275
21.2.1GameCenter登錄狀態················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

相關詞條

熱門詞條

聯絡我們