Scene and adding
Sprite objects on the screen is only part
of what we need to do. For a game to be a game we need to make things move
Action objects are an integral part of every game. Actions allow the
Node objects in time space. Want to move a
Point to another and use a callback when complete? No problem!
You can even create a
Action items to be performed on a
Node. You can change
Node properties like position, rotation and scale.
Scale. All games use Actions.
Taking a look at the sample code for this chapter, here are Actions in work:
and after 5 seconds the sprite will move to a new position:
Action objects are easy to create:
auto mySprite = Sprite::create("Blue_Front1.png"); // Move a sprite 50 pixels to the right, and 10 pixels to the top over 2 seconds. auto moveBy = MoveBy::create(2, Vec2(50,10)); mySprite->runAction(moveBy); // Move a sprite to a specific location over 2 seconds. auto moveTo = MoveTo::create(2, Vec2(50,10)); mySprite->runAction(moveTo);