Friday, January 22, 2016

Cocos2d-x C++ Actions

To move, scale, rotate etc of sprite are called action for making game more interesting. Action make the sprite change it properties in time.

Example of MoveTo Action;
//Create MoveTo Action
auto move = MoveTo::create(3, Vec2(100, 150));
//Assign MoveTo Action to spriteName
spriteName->runAction(move);
This represent sprite moving to coordinate 100,150 over 3 seconds

Source Code https://github.com/GameSculpt/Cocos2d-x-Tutorial-MoveTo-.git

Other actions examples;
RotateTo
//Rotate 180 degree over 2 seconds
auto rotate = RotateTo::create(2.0f, 180.0f);
spriteName->runAction(rotate);


ScaleTo
//Scale 2 times bigger over 2 seconds
auto scale = ScaleTo::create(2.0f, 2.0f);
spriteName->runAction(scale);

FadeOut
//Fade out sprite over 2 seconds
auto fade = FadeOut::create(2.0f);
spriteName->runAction(fade);

TintTo
//Tint to green over 2 seconds
auto tint = TintTo::create(2.0f, Color3B::GREEN);
spriteName->runAction(tint);

JumpTo
//Jump from center of screen to addition X=100 Y=100, 10 : jump height, 4 : number of jumps, over 2 seconds
auto jump = JumpTo::create(2.0f,Vec2(winSize.width/2 + 100,winSize.height/2 + 100), 10.0f, 4.0f);
spriteName->runAction(jump);



0 comments:

Post a Comment