Cocos2d-x uses action for various animation Effects

Source: Internet
Author: User

Monkey original, you are welcome to reprint, please note clearly! Thank you.

Address: http://blog.csdn.net/yanghuiliu/article/details/6933352

There are a lot of animation effects in the project, most of which are implemented using action. Of course, you can also implement it yourself at each frame. The principle is basically the same.

1. Fast jitter between left and right using ccmoveto.

CCPoint pointL=pointBg;CCPoint pointR=pointBg;pointL.x-=3;pointR.x+=3;CCMoveTo* moveLeft=CCMoveTo::actionWithDuration(0.08, pointL);CCMoveTo* moveRight=CCMoveTo::actionWithDuration(0.08, pointR);CCFiniteTimeAction* action= CCSequence::actions(moveLeft,moveRight,NULL);CCActionInterval* actionShake=CCRepeatForever::actionWithAction((CCActionInterval*)action);skillBg->stopAllActions();skillBg->runAction(reSkillAnim);

Pointbg is the Sprite you need to shake left and right.

Ccmoveto is where to move, the parameter is the moving time, And the destination coordinate point. (Ccmoveby is the distance between the current position, which is slightly different .)

As mentioned above, ccsequence can be used as a queue for executing an action. If it encounters null, it will end.

Because it is to implement different left and right movements, I wrap the left and right movements into a ccrepeatforever action, which repeatedly plays this action.


2. ccjumpto jumps from one place to another.

CCJumpTo* mJumpTo = CCJumpTo::actionWithDuration(0.2f, mToPosition, 30.0f, 1);

The first parameter is the long jump time, the second parameter is the jump target point, the third parameter is the maximum jump height, and the fourth parameter is the number of hops.

3. ccdelaytime can be used as the pause duration. ,

CCDelayTime *waiting=CCDelayTime::actionWithDuration(0.2f);

Pause for 0.2 seconds.


4. Zoom in/out ccscaleto. (Difference between ccscaleby and how much to zoom in/out)

CCScaleTo* scale=CCScaleTo::actionWithDuration(0.5, 0.2);

The time of the first parameter, the second parameter scaling multiple, = 1 normal size,> 1 zoom in, <1 zoom out


5. ccrotateto rotation angle. Same as above. Angle: 0-360.


6. ccwaves and ccshaky3d

CCActionInterval* waves = CCWaves::actionWithWaves(5, 20, true, false, ccg(15,10), 5);CCActionInterval* shaky = CCShaky3D::actionWithRange(4, false, ccg(15,10), 5);

Ccwaves Wave Effect and ccshaky3d vibration effect. It is executed in full screen mode. You can see the specific effect when you run it.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.