Cocos2d-x 3.xGame Development journey
Zhong Dilong
ISBN 978-7-121-24276-2
2014Published in October
Pricing: 79.00 RMB
516Page
16Open
Contents
The Cocos2d-x 3. x game development journey "is the upgrade of" Cocos2d-x game development journey ", modified some content after Cocos2d-x 2.0 edition advanced to 3.0 edition, added cocostudio, UI Editor, Cocos2d-x 3. X new features and network knowledge points. This article mainly introduces the commonly used API usage; how to get more about the Cocos2d-x API usage through the official demo; cocostudio and Cocos code ide basic usage; through 2 to 3 game instances to introduce the application of Cocos2d-x in the actual development; mobile network game development entry; in the actual mobile game development process encountered problems and solutions.
The Cocos2d-x 3. x game development tour "for Cocos2d-x beginners or have learned the Cocos2d-x 2.0 version want to continue to use Cocos2d-x 3. readers of Game Development in Version X are also suitable for those who have just entered the game development industry and want to learn about the problems and solutions encountered by mobile game developers in actual development.
Directory
Chapter 1 Opening Ceremony/1
1.1 appearance profile/1
1.2 admission requirements-this book is suitable for the audience/2
1.3 This content is a bit bad-book style/2
1.4 you need these skills-what do you need to learn Cocos2d-x/3
1.5 Why should we learn Cocos2d-x 3.0/4
1.6 first, let's find a warm home for our code-environment building/4
1.6.1 Black Storm vs2013/4
1.6.2 my Cocos2d-x version/5
1.6.3 we still need to make some preparations/6
1.6.4 semi-automatic environment variable configuration/6
1.6.5 let's take a look at the graduation design of our predecessors-run the official demo/8
1.7 advertising time-provide some learning resources/10
Chapter 12 helloworld/12
2.1 simple to unimaginable-run the helloworld project directly/12
2.2 trouble creating a Cocos2d-x project -- A New helloworld/14 was created successfully
2.2.1 create Cocos2d-x 3.0 Project/14
2.3 helloworld, not as simple as imagined-simple parsing of helloworld/16
2.3.1 how is helloworld displayed in the window/16
2.3.2 The scenario is not a real one/17
2.4 instance Arrival/20
2.4.1 digression-multiple projects in one project to avoid repeated compilation/20
2.4.2 create your own helloworld/23
Chapter 2 let's learn how to crawl/28
3.1 World Tour-scenario/28
3.2 The dominance of everything-Director/29
3.2.1 load the first scenario/29
3.2.2 simple switching scenario/29
3.2.3 switch scenario with special effects/31
3.2.4 complimentary-promotion and pop-up scenarios/33
3.3 you go to yours, I go to my -- Layer/35
3.4 more cute than the object-The genie came/36
3.5 I have to run the command-menu/37
3.6 As a backpacker-node/39
3.7 Cocos2d-x 3.0 new member -- value, vector, MAP/40
3.7.1 high capacity -- value/41
3.7.2 arrange for me -- Vector/42
3.7.3 check-MAP/44
3.7.4 super power of value-conversions between integers, floating-point numbers, and strings/46
Chapter 4 how to walk/47
4.1 guitar solo "City of the Sky"-Playing sound/47
4.2 controls 1-my favorite Nine Sisters and button events/48
4.2.1 hello, jiumei -- stretch pictures/48
4.2.2 solve the compilation error when using the extensions Library/49
4.2.3 matching of nine sisters and buttons/51
4.3 world of visualization-cocostudio UI Editor/53
The source code of this instance is: chapter4_2_scale9sprite/53
4.3.1 still using code to write the UI? Are you stupid?/53
4.3.2 drag only-UI editor Overview/54
4.3.3 richer UI-Import image resources/56
4.3.4 richer UI-export final file/58
4.3.5 display results-loading the UI/59 in the game
4.3.6 interaction-button listening event/62
More than 4.4 articles-advanced features of cocostudio UI Editor/65
4.4.1 death, death, and death
4.4.2 slide layer I want to hide/68
Chapter 2 let's learn how to fight/72
5.1 Action 1-simple motion/72
5.1.1 where do you want to go and how far do you want to go-moveTo and moveBy/72
5.1.2 I want to lose weight-scaleto and scaleby/74
5.1.3 card flip special effect-scaleto can be used for/77
5.1.4 debut-blink/77
5.2 Action 2-more complex motion/79
5.2.1 I want you to follow my route -- bezierto and bezierby/79
5.2.2 I didn't let you stop and repeatforever/81
5.2.3 perform the action together and jump one side by one -- sequence and spawn/82
5.3 Action 3-action monitoring/84
5.3.1 let me know when I get home-listener for Action termination/84
5.3.2 more convenient function callback-lambda/85
5.3.3 Action family genealogy/88
5.4 screen touch event/89
5.4.1 Initial Study on screen events/89
5.4.2 single touch-truncation event, monopoly of an object/91
5.4.3 multi-point touch-too weak, join up/94
Chapter 2 is the time to run-littlerunner/99
6.1 what is this game/99
6.2 find a leading character back-create a leading character genie/100
6.2.1 create a filter/100
6.2.2 create an object base class/101
6.2.3 create a main character class/102
6.2.4 create a game scenario/103
6.2.5 modify the game window size/106
6.3 In fact, she does not want to run-create an infinite rolling MAP/107
6.3.1 each frame can be operated-scheduleupdate initial study/107
6.3.2 tumble, map-unlimited map scrolling/109
6.4 Happy Time -- let the protagonist jump up/111
6.4.1 button Application -- create a jump button/111
6.4.2 jumpby Application -- add a jump action to the main character/112
6.5 money temptation-join monsters/114
6.5.1 creation of monsters/114
6.5.2 create a monster nest-create a monster Manager/116
6.5.3 greedy protagonist-monster collision detection/119
6.5.4 monsters cannot touch the main character-use a combination of minor troubles/122
6.5.5 when it hurts, move back-increase the actions when the protagonist is injured/123
6.6 Monitor everything-create score tags, blood records, and other attribute objects/125
Chapter 2 genie Season 2/7th
7.1 a great wave of genie attacks-defects drawn by a large number of Elves/129
7.1.1 2.0 memories-a large number of Sprite embarrassment/129
7.1.2 new feature in 3.0 -- auto-batching/130
7.1.3 no perfect thing-auto-batching "Control Manual"/131
7.1.4 who asked the question -- setglobalzorder, setlocalzorder, setorderofarrival/134
7.1.5 complimentary dessert-in-depth analysis of auto-batching source code/138
7.2 install the same genie on the car-use spritebatchnode to optimize rendering/144
7.2.1 one-time rendering -- highlights of spritebatchnode/144
7.2.2 what is texture-texture simple explanation/146
7.3 What should I do if I encounter different Genie? Use the texturepacker tool/147
7.3.1 same image, same texture/148
7.3.2 Package Multiple images together/149
7.3.3 loaded and packaged images/151
7.4 is an animation, not an action-animation/152
7.4.1 create an animation with the image before packaging/152
7.4.2 create an animation with the packaged image/154
7.4.3 additional gift-animation creation helper class/156
Chapter 4 running game instances/8th
8.1 richer world-use tiled MAP/160
8.1.1 world was born-create a running scenario/160
8.1.2 tiled map: Use tiled map editor to create a map file/162
8.1.3 Have you reported an error? -- Common tiled editor path error/163
8.2 hey, train new people-create new protagonists/164
8.2.1 creation of the main character-create an entity class and a main character class/164
8.2.2 fixed protagonist birth point-Object layer usage/167
8.2.3 run the main character-Add the main character animation/169
8.3 more intelligent protagonist-Add a role Controller/170
8.3.1 create a controller base class/170
8.3.2 run with it -- Mobile controller of the main character/172
8.3.3 focus on the main character-rolling the map with the main character/175
8.4 more content/178
8.4.1 move the main character up/down-third-party mobile Controller/178
8.4.2 add obstacle -- Use of tiled obstacle Layer/181
8.4.3 add items that can be eaten and conditions for victory/187
Chapter 1 how to use multithreading for timer? You are crazy -- schedule is very powerful/191
9.1 I love single thread -- Schedule introduction/191
9.2 Each frame has me -- scheduleupdate and update/191
9.3 The timer can do this-schedule and callback function/193
9.3.1 do not call the UPDATE function. Call your own function/193
9.3.2 real timer/194
9.4 stop everything -- unschedule/195
9.5 trigger can do this-scheduleonce and callback function/197
9.6 accurate timing function-making Timer/198
9.6.1 schedule is not so punctual-the longer it takes/198
9.6.2 more accurate timing-no slower time/200
9.6.3 time bomb creation-convenient time callback function encapsulation/203
9.7 extra gifts, I always pay attention to the girl I am in crush-Observer mode/205
9.7.1 who do you like? I will help you pay attention to-Observer mode literacy/205
9.7.2 observer mode tool class provided by Cocos2d-x-icationicationcenter/206
9.7.3 difference between addobserver and postnotification function in data transmission/209
9.7.4 additional gifts-self-implemented simple observer/211
Chapter 4 survival training/10th
Master 10.1 is gone. What do you do? Learn to view the official demo/216
10.2 learn sooner or later -- Learn to view the demo source code/217
10.3 don't forget Open Source-learn to view Cocos2d-x source code/218
10.3.1 why addobserver and postnotification cannot transmit data at the same time/218
10.4 The best choice of things, useless will be eliminated-retain and release/221
10.4.1 Why retain/221
10.4.2 real murderer autorelease/222
10.4.3 actual code point/222
10.4.4 principle/224
10.4.5 actual situation/225
When will retain/225 be required?
10.5 what? You forgot to save your memory? We have been together for ten years-saving data/226
10.6 I can get rid of the nightmare of compilation-read the CSV configuration file/227
10.6.1 what is CSV file-CSV format file literacy/228
How to Create a CSV file/228
10.6.3 push-compile the string tool class/229
10.6.4 everything is an object-CSV file object class/231
10.6.5 enter the topic-write CSV file reading tool class/233
10.7 hit the compilation nightmare again-more convenient expansion of JSON/238
10.7.1 what is JSON-Basic Literacy/238
10.7.2 get your weapon-import the jsoncpp parser Library/239
10.7.3 is that simple-read the JSON file/241
10.7.4 advanced challenge-reading JSON files with nested structures/242
10.7.5 advanced challenge-read the JSON file of the array structure/243
10.7.6 advanced challenge-output JSON file/244
Chapter 4 do not eat while sleeping-finite state machine/11th
11.1 spend 5 minutes telling you what a finite state machine/247
11.1.1 simple understanding/247
11.1.2 a very "fun" game/247
11.1.3 class for implementing a simple finite state machine/248
11.2 status mode I am fat, but I am very strong/251
11.2.1 what is status mode/251
11.2.2 implement finite state machine/252 in State Mode
11.3 The real state machine is coming/258
11.3.1 create a state machine class/258
11.3.2 released wood category/260
11.4 event-driven, not as powerful as you can imagine/263
11.4.1 discard the UPDATE function completely-new state machine class/263
11.4.2 more intelligent status/266
11.4.3 new operations/267
Chapter 1 I am better than CSV-powerful Lua/12th
12.1 connecting Lua and C ++/269
12.1.1 Lua stack and global table/269
12.1.2 first communication between Lua and C ++/269
12.2 Demo: Lua and C ++ hands-on/270
12.2.1 introduce Lua database/271
12.2.2 start/272
12.2.3 execute Lua script/273
12.2.4 reset the stack top index and place the global variables in the stack/274
12.2.5 In the last step, C ++ retrieves the string/274
12.3 simple parsing of Lua stack/276
12.4 difficult to obtain the Lua table structure data/276
12.4.1 what is table/277
12.4.2 get table variable/277
12.4.3 functions of lua_gettable/277
12.5 C ++ calls Lua function/280
12.6 Lua calls C ++ functions/281
Chapter 2 self-reliance-write a UI module by yourself/13th
13.1 At the beginning, you must take it easy-Overview of the UI module ideas/285
13.1.1 what can it do for us-functions included in the UI module/285
13.1.2 view of the UI module design ideas/286
13.2 XML file and attribute module/287
13.2.1 source of everything-xml configuration file of UI/287
13.2.2 knowledge Supplement 1 -- tinyxml introduction/289
13.2.3 knowledge Supplement 2 -- tinyxml helloworld/289
13.2.4 knowledge Supplement 3 -- use tinyxml to read the xml configuration file of the UI module/292
13.2.5 encapsulation, we need to remember encapsulation-xml tag Node object/296
13.2.6 I am responsible for saving and you are responsible for modifying the -- XML tag node attribute configurator/302
13.3 taste the sweetness -- create a control/305
13.4 leading role-component/308
13.4.1 control base class -- mmbase/308
13.4.2 common window control -- mmnormalwin/309
13.4.3 label control -- mmlabel/311
13.4.4 dessert now -- test the new control class/312
13.5 control management module/314
13.5.1 I am the boss -- mmwinmanager Control Manager/314
13.5.2 I am a pioneer-mmwinsystem Control System/318
13.5.3 I am the frontend -- mmwindesktop control top desktop/321
13.6 control factory/322
13.6.1 abstract factory-mmwinbasefactory/322
13.6.2 control factory-mmwinfactory/323
13.6.3 decoration factory of mmwinproperityfactory/324
13.6.4 the last thing -- run the project/326
Chapter 5 dedication-The card tower anti-DDoS game (Part 1)/14th, which was born due to laziness
14.1 opening-last game instance/329
14.1.1 why anti-tower games/329
14.1.2 function introduction to card tower guard-what do we learn/329
14.2 departure-level editor/330
14.2.1 a hero and a pitfall-turret coordinate Editor/331
14.2.2 follow the path I gave-monster coordinate Editor/348
14.2.3 add more convenient operations/356
14.3 cutting firewood by mistake-preparation knowledge/361
14.3.1 director's assistant-scenario Manager/361
14.3.2 Data Reading module/364
14.3.3 global parameter/365
14.3.4 can I speak English? No, Chinese-i18n tool class/366
Chapter 4 dedication-The card tower anti-DDoS game (Part 2)/15th, which was born due to laziness
15.1 heroes/372
15.1.1 level creation scenario/372
15.1.2 map layer/373
15.1.3 entity base class/375
15.1.4 hero Manager 1 -- artillery target/378
15.1.5 hero Manager 2 -- HERO object/382
15.1.6 hero Manager 3-relationship between the cannon and the hero/386
15.1.7 hero manager 4 -- added the hero creation function/387
15.2 monsters/389
15.2.1 monster Manager/389
15.2.2 mobile controller 1 -- controller base class/394
15.2.3 mobile controller 2 -- Mobile controller base class/394
15.2.4 mobile controller 3 -- move by the specified coordinate list/396
15.2.5 monsters come/400
15.3 hero attack/404
15.3.1 A hero's attack process/404
15.3.2 get the monster list in hero/405
15.3.3 search for and lock the target/406
15.3.4 hero attack/407
15.3.5 bullet Manager 1 -- bullet class/409
15.3.6 bullet Manager 2 -- bullet Manager/413
15.3.7 bullet Manager 3 -- the hero starts to launch a bullet/416
15.4 gorgeous decoration/417
15.4.1 monster blood records/417
15.4.2 turret OPERATION button-hero upgrade/419
15.4.3 monster start and end magic servers/425
Chapter 5 dedication-The card tower guard game (final)/16th, which was born due to laziness
16.1 level information UI/428
16.1.1 use the UI editor to create the level information panel/428
16.1.2 level information data refresh-icationicationcenter application/431
16.1.3 monster quantity refresh/435
16.1.4 monsters Rest in Peace-Number of souls in the dead tower refresh/435
16.1.5 bastion rest-after a monster arrives at the bastion, the magic value is deducted/436
16.1.6 monster upgrade-hero upgrade deduct tower soul/438
16.2 curtain call/439
16.2.1 level selection-load game/439 based on the number of levels
16.2.2 victory condition judgment/443
16.2.3 failure condition judgment/446
16.3 port the game to the Android platform/447
16.3.1 construction of a silly Android environment 1 -- Preparation/447
16.3.2 construction of a silly Android environment 2 -- decompression and installation/448
16.3.3 silly Android environment construction 3 -- test/451
16.3.4 preparations-import Android Project/453
16.3.5 permanent -- modify the Android. mk file/455
16.3.6 start compiling -- build_native.py file/458
Chapter 2 I don't want to play games by myself-online game entry/17th
17.1 only one stepping stone for you-what this chapter brings to you/460
17.2 left-hand and right-hand circles-multithreading/461
17.3 start from the simplest-from establishing a connection to receive data/464
17.3.1 secretly connect to others-use odsocket to establish a connection with the server/465
17.3.2 not running-write a test server/467
17.3.3 get down to the truth -- write our Cocos2d-x client/469
17.4 you have to be a real online game-server-client interaction logic/471
17.4.1 multi-thread evasion-safer data receiving and processing/471
17.4.2 enter the game-the server notifies the client to enter the game scenario/476
17.4.3 more people-request the number of online players and add all players to the scene/480
17.4.4 new players should report to the MIIT-new players should be added to notify online players/484
Chapter 5 additional things/18th
18.1 Common Errors and Solutions/486
18.1.1 when a variable parameter function is called, an error is always reported/486
18.1.2 external symbols (or commands) that cannot be parsed/486
18.1.3 Android port compiling error -- undefined reference to/487
18.1.4 the label becomes a Black Block-A bug caused by multithreading/487
18.1.5 interrupt window/487
18.1.6 error reported after repeated switching/488
18.2 game release process (overview)/489
18.2.1 add ad SDK/489 to the game
18.2.2 add statistics SDK/490
18.2.3 upload the game to various markets/491
18.3 future trends/492
18.3.1 cloud backend service/492
18.3.2 social SDK/492
18.3.3 Cocos code ides/493
18.3.4 cocostudio/493
18.4 security awareness/493
18.4.1 encrypted data type, reject game modifier/494
18.4.2 tips for preventing package parties/495
18.5 game development thinking/497
18.5.1 no matter how fast the game is, one frame is one frame. We can do a lot/497
18.5.2 use casual bugs to create more methods/497
18.6 last/498
18.6.1 the fastest way to find wood/498
18.6.2 surprise to readers-ding xiaoruo's message/499
18.6.3 Please provide your comments and bugs/499
Preface
From 2.0 to 3.0
When I first came into touch with Cocos2d-x, it happened to release version 2.0, starting from the ERA 1. X to the ERA 2. x. At that time, I was very lucky because 2. x made a lot of changes compared to 1. X, and I don't need to experience the "Resentment" caused by such changes ".
A year ago, I tried my best to write "Cocos2d-x game development journey" published, was still Cocos2d-x 2.0 era. Some readers like its style, but also some readers hate it nagging, no matter what, it seems to help a lot of readers into the door of Cocos2d-x.
However, since a year, the Cocos2d-x 3.0 version gradually surfaced, we want to usher in the 3.0 era, I have the honor to once again witness this era of time. 3.0 will replace 2.0, so it is the Cocos2d-x 3. x game development journey.
This is not entirely new content
The main purpose of this book is to upgrade the content of Version 2.0 to version 3.0. Instead of writing a new book, most of the content structures are the same and can be seen from the directory. If we say this is a brand new book with completely different content, then I may have become a liar dedicated to writing books. When I was writing a 2.0 book, I had spent all of my accumulated knowledge over the past few years. Now it's just a year. I have accumulated this year, but it's not enough to write a new book.
Therefore, I would like to clarify the situation in the preface to avoid unnecessary misunderstanding with readers.
Of course, I have spent a lot of effort to check, modify, and optimize the sentence code, and adjust, modify, and add a line of text, in addition, it has added some 3.0 unique new content, including online games, AD access, and game publishing.
I don't want to "CREATE" any more
A year ago, when I finished writing the 2.0 version of books, I was tired and tired of writing books. Then I told myself, "I will never write any more books in my life !", Just like a mother who just gave birth to a child, she had no courage to continue.
However, just like all mothers, after a long time, they forget the pain and only remember the joy of their children. I don't know why I decided to write this book. Maybe too many readers complained that the previous book version was too old. So, this Cocos2d-x 3. x book was born. Now, I still want to say that I will never write any more books in my life! Haha, maybe this is an excited and satisfied roar after doing everything done.
So I hope this book will continue to help beginners start their game development journey happily.
Main content of this book
This book consists of 18 chapters, if the reader has no experience in the use of Cocos2d-x, it is recommended to read from Chapter 1st. For readers who have the foundation of Cocos2d-x, I have listed the main contents of each chapter for your reference.
Chapter 1st: briefly introduces the book writing philosophy, Cocos2d-x 3.0 environment to build and recommend some learning resources.
2nd ~ Chapter 3: introduce the basic knowledge and structure of Cocos2d-x 3.0.
4th ~ Chapter 6: describes how to use the cocostudio UI Editor, actions, and screen touch events. A simple game instance is used to concatenate the content of the previous chapter.
7th ~ Chapter 10: To introduce the higher-order content of Cocos2d-x 3.0, including rendering efficiency improvement, animation, texturepacker image packaging, tiled map game instances, timers, message distribution, function callback, memory management, data storage, CSV file reading, JSON file read/write.
11th ~ Chapter 12: Introduce the Communication Knowledge of Lua and C ++ and the basic knowledge and application of finite state machines.
Chapter 13th: Share my own self-developed Cocos2d-x 3.0-based custom UI module, detailed introduction of custom UI module design ideas and implementation process.
14th ~ Chapter 16: describes in detail the last game instance card tower guard, which uses most of the knowledge introduced in this book. As the last example of this book, I used three chapters to detail the game's ideas, framework setup, and function implementation processes.
Chapter 2: describes the basic process of online game development, and describes the client that can interact with the server.
Chapter 2: Share my previous mistakes and solutions, and introduce the knowledge of game publishing, AD access, and security.
What is different from version 2.0?
Maybe some readers have bought the 2.0 version of the "Cocos2d-x game development journey", here lists the book and the 2.0 version of the book of the difference, for readers to refer:
1. Upgrade all codes to version 3.0.
2. delete some outdated content and upgrade and optimize the original content.
3. Added 3.0 new features such as value, vector, MAP, 3.0 touch mechanism, Lambda function, and auto-batching.
4. added content such as JSON, cocostudio UI editor, and online game.
5. added the game release process, future trends, and security processing content.
Thank you
I think what I should like to thank most this time is those who recognize me and those who can understand the Humorous Style in the book. You let me know that I am not a mental patient ".
Finally, I would like to thank my family for not only providing support but a complete and happy family. In addition, I have to thank Bai Ding xiaoruo next to this book, for her willingness to grant me the permission to use her name, and for her humorous inspiration.
I would like to dedicate this book to my lovely family and friends.
Due to the limited level, there will inevitably be errors in the book. I hope readers can correct them more. You are also welcome to interact with me on questions in my blog.
Zhong Dilong
2014.08.05
Cocos2d-x 3. x game development tour