Run action (basic summary) "Seven basic Actions" "Three action list"

Source: Internet
Author: User

① Mobile (move)

MoveTo and Moveby represent absolute and relative coordinates.

1 //Move the node (target) to the absolute coordinates (50,0) within two seconds2Auto MoveTo = Moveto::create (2, VEC2 ( -,0));3 //node Run Action4Mysprite->runaction (moveTo);5 //moving the node (target) to relative coordinates (50,0) in two seconds is equivalent to moving 50 pixels to the right.6Auto Moveby = Moveby::create (2, VEC2 ( -,0));7 //node Run Action8Mysprite->runaction (Moveby);
② Rotation (Rotate)
1 // Rotate the node to 40 degrees within two seconds 2 Auto Rotateto = rotateto::create (2.0f40.0f); 3 mysprite->runaction (rotateto); 4 // within two seconds, the node rotates 40 degrees clockwise 5 Auto Rotateby = rotateby::create (2.0f40.0f); 6 mysprite->runaction (Rotateby);
③ Scaling (Scale)
1 //after two seconds, the scale is 3 times times the relative size. 2Auto Scaleby = Scaleby::create (2.0f,3.0f);3Mysprite->runaction (Scaleby);4 //after two seconds, the x-axis of the relative size is scaled twice times, and the y-axis is 3 times times. 5Auto Scaleby = Scaleby::create (2.0f,2.0f,3.0f);6Mysprite->runaction (Scaleby);7 //after two seconds, the scale is 3 times times the absolute size. 8Auto Scaleto = Scaleto::create (2.0f,3.0f);9Mysprite->runaction (scaleto);Ten //after two seconds, scale the absolute size of the x-axis twice times, and the y-axis 3 times times.  OneAuto Scaleto = Scaleto::create (2.0f,2.0f,3.0f); AMysprite->runaction (Scaleto);
④ fade in (Fade)
1 // a second later, the nodes became more and more 2 Auto fadeIn = fadein::create (1.0f); 3 mysprite->runaction (fadeIn); 4 // after two seconds, the node becomes invisible. 5 Auto FadeOut = fadeout::create (2.0f); 6 mysprite->runaction (fadeOut);
⑤ Tone (Tint)
1 //in two seconds, the node hue changes to an RGB value2Auto Tintto = Tintto::create (2.0f,120.0f,232.0f,254.0f);3Mysprite->runaction (Tintto);4 //within two seconds, the node tones change relative RGB values (increase???? ) 5Auto Tintby = Tintby::create (2.0f,120.0f,232.0f,254.0f);6Mysprite->runaction (Tintby);
⑥ Animation (animate)
1Vector<spriteframe*>Animframes;2Animframes.reserve (4);3Animframes.pushback (Spriteframe::create ("Blue_front1.png", Rect (0,0, $,Bayi)));4Animframes.pushback (Spriteframe::create ("Blue_left1.png", Rect (0,0, $,Bayi)));5Animframes.pushback (Spriteframe::create ("Blue_back1.png", Rect (0,0, $,Bayi)));6Animframes.pushback (Spriteframe::create ("Blue_right1.png", Rect (0,0, $,Bayi)));7 //Create an animation from a frame8animation* Animation = Animation::createwithspriteframes (Animframes,0.1f);9animate* animate =animate::create (animation);Ten //always run repeatedly OneMysprite->runaction (Repeatforever::create (animate));
⑦ deceleration (easing)

//Create a Moveby action to move the sprite down. Auto move = Moveby::create (2, VEC2 ( $, Dirs->getvisiblesize () .height-newsprite2->getcontentsize (). height)); Auto Move_back= move->reverse ();//Create a Bouncein Ease actionAuto move_ease_in = easebouncein::create (move->clone ()); //Create a delay (wait) to place between the two base actionsAuto delay = delaytime::create (0.25f); //creates an action sequence and puts the various underlying actions into the sequence for runningAuto SEQ1 =sequence::create (move_ease_in, delay, move_ease_in_back, delay-Clone (), nullptr); //always run this sequence of actionsMysprite->runaction (Repeatforever::create (seq1));

In order to facilitate the movement, there are three ways to do this:

Sequence (sequence), Spawn, Reverse (reverse order)

(i) Sequence action and how to execute it

SequenceYou can make a series of action objects execute sequentially. This series of objects can be any number of action objects, functions, or even another sequence action. Function? Yes! There is a Callfunc object in Cocos2d-x that allows you to create a function () and can be passed into Sequence execution. This allows you to add your own function functions to the sequence action object, rather than just the action object provided in the Cocos2d-x. The following example is the state when the sequence action is executed:

1 //Create several actions2Auto jump = Jumpby::create (0.5, VEC2 (0,0), -,1);3  4Auto rotate = rotateto::create (2.0f,Ten);5  6 //create several callback functions7Auto Callbackjump =callfunc::create ([] () {8Log"jumped!");9 });Ten   OneAuto Callbackrotate =callfunc::create ([] () { ALog"rotated!"); - }); -   the //Create a sequence, with actions and callbacks -Auto seq =sequence::create (jump, callbackjump, rotate, callbackrotate, nullptr); -   - //Run it +Mysprite->runaction (seq);
(ii) Spawn

SpawnUnlike a Sequence similar one, all actions are executed simultaneously when using spawn. You can have a lot of action objects, even other spawn objects.

SpawnHas the same effect as running multiple successive runaction () statements. However, Spawn the advantage of using it is that you can put it in a sequence to achieve a specific effect.

and Runaction () is not possible. SpawnThere are Sequence many powerful features that will be implemented and used together.

1 //Create several actions2Auto Moveby = Moveby::create (Ten, VEC2 ( -, -));3Auto FadeTo = Fadeto::create (2.0f,120.0f);4Auto Scaleby = Scaleby::create (2.0f,3.0f);5 //Create a Spawn to use6Auto Myspawn =spawn::createwithtwoactions (Scaleby, fadeTo);7 //connect everything together in a sequence8Auto seq =sequence::create (Moveby, Myspawn, Moveby, nullptr);9 //Run itTenMysprite->runaction (seq);
(c) Reverse (reverse order)

The reverse function is exactly like its name, for example, when running a series of actions, you can call the reserve () function to reverse the action. However, this is not just a simple reverse run, but also the original Sequence and Spawn the properties are converted to reverse.

1 // reverse a sequence, spawn, or an action 2 mysprite->runaction (Myspawn->reverse ());

Reference: http://cn.cocos2d-x.org/tutorial/show?id=2035

Run action (basic summary) "Seven basic Actions" "Three action list"

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.