Game Development Reference
In-Depth Information
Time for action - creating actions with
Cocos2d-x
Creating actions with Cocos2d-x is a very simple process:
1. 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();
2. Actions can be combined in many different forms. Here, the retained
_swingHealth action is a RepeatForever action of Sequence that will ro-
tate the health sprite first one way, then the other, with EaseInOut wrapping the
RotateTo action. RotateTo takes 1.2 seconds to rotate the sprite first to -10
degrees and then to 10 . And the easing has a value of 2 , which I suggest you ex-
periment with to get a sense of what it means visually. Next we add three more ac-
tions:
//action sequence for shockwave: fade out, callback
when //done
_shockwaveSequence = Sequence::create(
FadeOut::create(1.0f),
CallFunc::create(std::bind(&GameLayer::shockwaveDone,
this)), nullptr);
_shockwaveSequence->retain();
//action to grow bomb
_growBomb = ScaleTo::create(6.0f, 1.0);
_growBomb->retain();
Search WWH ::




Custom Search