Book Image

Cocos2d-x Cookbook

By : Akihiro Matsuura
Book Image

Cocos2d-x Cookbook

By: Akihiro Matsuura

Overview of this book

Table of Contents (18 chapters)
Cocos2d-x Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating actions


Cocos2d-x has a lot of actions, for example, move, jump, rotate, and so on. We often use these actions in our games. This is similar to an animation, when the characters in a game start their action, the game will come alive. In this recipe you will learn how to use a lot of actions.

How to do it...

Actions are very important effects in a game. Cocos2d-x allows you to use various actions.

Move

To move a sprite by a specified point over two seconds, you can use the following command:

auto move = MoveBy::create(2.0f, Vec2(100, 100));
sprite->runAction(move);

To move a sprite to a specified point over two seconds, you can use the following command:

auto move = MoveTo::create(2.0f, Vec2(100, 100));
sprite->runAction(move);

Scale

To uniformly scale a sprite by 3x over two seconds, use the following command:

auto scale = ScaleBy::create(2.0f, 3.0f);
sprite->runAction(scale);

To scale the X axis by 5x, and Y axis by 3x over two seconds, use the following command:

auto scale = ScaleBy...