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 ...

Get Python Game Programming By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.