Cocos2d actions
In our previous game, we manipulated our sprites directly through their members, especially the position
attribute. The game loop updated each actor with the elapsed time from the previous frame.
However, our tower defense game will be based mainly on cocos2d actions, which are orders to modify object attributes such as the position, rotation, or scale. They are executed by calling the do()
method of the CocosNode
class. Therefore, any sprite, layer, or scene can be a valid target of an action.
The actions that we will cover in this section can be divided into two main groups: interval actions and instant actions.
Interval actions
These actions have a duration, and their execution ends after that certain duration. For instance, if we want to move a sprite to a certain position, we do not want it to happen immediately but last a fixed amount of time, giving the impression that it moves with a determined speed. This can be achieved with the MoveTo
action:
import cocos import cocos...