Cocos2dx 3.0 transition article 13 action usage starts with a story

Source: Internet
Author: User

This blog is from star 530. For more information, see the source. Http://blog.csdn.net/start530/article/details/20153367
-------------
How can I play an action? That is, runAction.
If you think this article is still writing the usage of actions such as MoveTo and SacleTo, you will be wrong. That's not good enough. Of course, things like Sequence and Spawn will also involve a little bit. So what should I write? Our story starts from here.

First, we will create two genie and name them boy and girl.

Auto size = Director: getInstance ()-> getWinSize (); auto boy = Sprite: create ("boy.png"); boy-> setPosition (Point (0, size. height/2); // set the location of the boy to the leftmost this-> addChild (boy, 1); auto girl = Sprite: create ("girl.png "); girl-> setPosition (Point (size. width, size. height/2); // set the girl's position to the rightmost this-> addChild (girl, 1 );

(Boys and girls didn't know each other at the beginning of the story until one day they met)
Boy and girl simultaneously move to the middle of the scene

Boy-> runAction (MoveTo: create (1.0f, Point (size. width/2-20, size. height/2); // boy is faster than girl. Girl-> runAction (MoveTo: create (1.5f, Point (size. width/2 + 10, size. height/2 )));

(Boy was stunned when he saw girl. He knows that she is the one he has been looking. This is love at first sight)
Boy expressed his excitement by rotating more than 360 of his body's blood. There are two manifestations:

// 1. Full scaling while rotating the side. boy-> runAction (Spawn: create (RotateBy: create (1.0f, 360), ScaleTo: create (1.0f, 1.2f ), NULL); // 2. First rotate and then expand the whole body. boy-> runAction (Sequence: create (RotateBy: create (1.0f, 360), ScaleTo :: create (1.0f, 1.2f), NULL ));
(Girl sees the bloat boy, so she can't help but think that boy is a great hero !), As a result)
The action shown here is that after the boy rotation + amplification, the girl will show her... what is her? By the way, women are more lively and should jump up. Well, girl jumped up.

// The point here is how can a girl execute her action after the boy completes the action? There are several ways to achieve this: // 1. Use delayed DelayTime, that is, after the boy completes the motion, the delay is several seconds, and then the girl motion // delay is 2.5 s, 3 hops in 1 s, 100 pixels in height, and 30 pixels in girl-> runAction (Sequence: create (DelayTime: create (2.5f), JumpBy :: create (1.0f, Point (30,0), 100,3), NULL); // 2. Use the callback function. After the boy completes, write a lambda expression to implement the actions that the girl wants to do (for the use of lambda expressions, refer to my previous blog) boy-> runAction (Sequence: create (RotateBy: create (1.0f, 360), ScaleTo: create (1.0f, 1.2f), CallFunc: create ([=] () {// jump 3 times in 1 s time, jump height 100 pixels, and 30 pixels are moved to the right. girl-> runAction (JumpBy: create (1.0f, Point (30,0), 100,3) ;}, NULL )); // 3. Use the ready-made interface TargetedAction (); auto jump = JumpBy: create (1.0f, Point (30,0), 100,3 ); // first write a jump action auto targetAct = TargetedAction: create (girl, jump); // write a target action, put the action executor girl and the Action jump to be executed into it // put the girl's target action into the boy's sequence to go to boy-> runAction (Sequence: create (RotateBy :: create (1.0f, 360), ScaleTo: create (1.0f, 1.2f), targetAct, NULL ));
(The last story is that the two of them were together very quickly. Although they didn't know each other for a long time, they had enough time to know each other and understand each other. It takes four years to prove that your vision is correct)
A lover eventually becomes a genus. At the end of the story, I can express my blessings to them with a flickering heart. Hope they will be together forever !!!

// Create a frame-by-frame animation auto spriteFrameCache = SpriteFrameCache: sharedSpriteFrameCache (); spriteFrameCache-> addSpriteFramesWithFile ("heart. plist "); // put the plist of the animated image into the cache. SpriteFrame * frame = NULL; auto frameArray = Array: create (); for (int I = 0; I <10; I ++) {frame = spriteFrameCache-> spriteFrameByName (CCString: createWithFormat ("ss0000d.png", "heart", I)-> getCString ()); frameArray-> addObject (frame);} auto animation = Animation: createWithSpriteFrames (frameArray, 0.15f); auto animate = Animate: create (animation ); // create an animation auto heard_sp = Sprite: create ("heart.png"); heard_sp-> setPosition (Point (size. width/2, size. height-200); heard_sp-> runAction (animate); // play the animation this-> addChild (heard_sp, 2 );

The story is simple, the process is not so easy, and the ending is not as beautiful as you think.




This blog is from star 530. For more information, see the source. Http://blog.csdn.net/start530/article/details/20153367

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.