ผลต่างระหว่างรุ่นของ "01219245/cocos2d/Actions"
Jittat (คุย | มีส่วนร่วม) |
Jittat (คุย | มีส่วนร่วม) |
||
แถว 4: | แถว 4: | ||
== Actions == | == Actions == | ||
+ | Using a combination of states and <tt>update</tt> method is very useful when we want to (micro) manage our objects. However, sometimes, we just want to tell object to do something like jumping or falling and do not want to keep track of these action. | ||
+ | |||
+ | For example, when our flappy dot dies, we want it to fall down to the ground. If we use states, we might want to add code to move the sprite downwards slighly in <tt>update</tt> method and to keep track that the dot reaches the ground. It will be easier if you can just tell the dot to fall down, and then stop worrying about it as the object shall move accordingly by itself (or by some magics). In Cocos2d-html5, there is a mechanism for performing that kind of work, called '''actions''' (See [http://www.cocos2d-x.org/reference/html5-js/V2.2.2/index.html reference here], type action in to the search box). (Read an overview for C++ version in Cocos2d-x [http://www.cocos2d-x.org/wiki/Actions here].) | ||
+ | |||
+ | We shall learn how to use actions by examples. | ||
=== Falling dot === | === Falling dot === |
รุ่นแก้ไขเมื่อ 02:05, 16 กุมภาพันธ์ 2557
- This is part of 01219245.
In this tutorial, we shall not create a new game, but we will learn a few useful techniques for making our game more engaging.
Actions
Using a combination of states and update method is very useful when we want to (micro) manage our objects. However, sometimes, we just want to tell object to do something like jumping or falling and do not want to keep track of these action.
For example, when our flappy dot dies, we want it to fall down to the ground. If we use states, we might want to add code to move the sprite downwards slighly in update method and to keep track that the dot reaches the ground. It will be easier if you can just tell the dot to fall down, and then stop worrying about it as the object shall move accordingly by itself (or by some magics). In Cocos2d-html5, there is a mechanism for performing that kind of work, called actions (See reference here, type action in to the search box). (Read an overview for C++ version in Cocos2d-x here.)
We shall learn how to use actions by examples.