Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Game Programming By Example

You're reading from   Python Game Programming By Example A pragmatic guide for developing your own games with Python

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781785281532
Length 230 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime