Time for action – creating actions with Cocos2d-x
Creating actions with Cocos2d-x is a very simple process:
Inside our
createActions
method, we will instantiate the actions we can use repeatedly in our game. Let's create our first actions:void GameLayer::createActions() { //swing action for health drops auto easeSwing = Sequence::create( EaseInOut::create(RotateTo::create(1.2f, -10), 2), EaseInOut::create(RotateTo::create(1.2f, 10), 2), nullptr);//mark the end of a sequence with a nullptr _swingHealth = RepeatForever::create( (ActionInterval *) easeSwing ); _swingHealth->retain();
Actions can be combined in many different forms. Here, the retained
_swingHealth
action is aRepeatForever
action ofSequence
that will rotate the health sprite first one way, then the other, withEaseInOut
wrapping theRotateTo
action.RotateTo
takes1.2
seconds to rotate the sprite first to-10
degrees and then to10
. And the easing has a value of2
, which I suggest you experiment with to get a sense...