Cocos Learning notes--variable speed movements speed and actionease_cocos2d-x

Source: Internet
Author: User
Tags addchild

The variable speed movement is similar to the compound action, and it is also a special action which can carry out any action according to the speed of change. The biggest difference between variable speed and compound action is that the compound action is simply a combination of a series of actions, and the speed of the action in combination with a series of actions to change the speed of execution.

Variable speed movements are mainly divided into 2 categories: speed and actionease.

I. Speed

Used to change the speed of an action linearly, that is, to change the overall speed of an action exponentially. The speed is equivalent to a wrapper that wraps the action needed to change the speed.

Speed class source can be seen in the Ccaction class:

Class Cc_dll Speed:public Action
{
    ...
    Static speed* Create (actioninterval* action, float Speed);
    inline float getspeed (void) const {return _speed;}
    inline void Setspeed (float speed) {_speed = speed;}
    ......
}

As you can see, the speed class is directly inherited from the action class. The Create () method receives 2 parameters, the first is the action to be wrapped, must be actioninterval type of action, that is, simple continuous action or composite action, can not be instantaneous action; The second parameter is a float-type speed value speed, This speed is the method to package the action of the original speed of the execution of multiples, such as speed=0.5, on behalf of the packaging after the speed changed to 0.5 times times, speed=2, on behalf of the packaging after the speed is twice times the original speed.


Give me a chestnut:

Create a sprite
auto sprite = sprite::create ("haha.jpg");

Add
this->addchild (sprite);

Create MoveTo action
Auto _moveto = Moveto::create (3.0,VEC2 (920,320));

Create speed Variable speed action
//parameter: 1. Action 2. The amount of the original speed of the packaging action
Auto _speed = speed::create (_moveto,2);

Perform action
sprite->runaction (_speed);


Two. Actionease

Although speed can change the speed of the action, but only proportionally change the speed. Actionease can achieve the movement of the speed of movement from fast to slow, speed changes over time. The class contains a wide range of buffer motions: exponential buffering, sinusoidal buffering, resilient buffering, jump buffering, and shock-resilience buffers, etc. Each kind of buffering movement basically contains 3 different time transformations: In, out and inout, what are the 3 transformations? In short, in is the acceleration at the start of the movement, the out is slowed at the end of the movement, the inout contains both, which is the first acceleration and deceleration.

We can look at the source of the Actionease class first:

Class Cc_dll Actionease:public Actioninterval

As you can see in this statement, the Actionease class is inherited from the Actioninterval class, so it is also a continuous action.


Here is a statement of all kinds of buffer movements:

Index buffer class Cc_dll Easeexponentialin:public actionease class Cc_dll easeexponentialout:public Actionease class CC_DLL Easeexponentialinout:public actionease//sine buffer class Cc_dll easesinein:public Actionease class Cc_dll EaseSineOut: Public actionease class Cc_dll Easesineinout:public actionease//Resilient buffer class Cc_dll Easeelastic:public actionease CLA SS Cc_dll Easeelasticin:public easeelastic class Cc_dll Easeelasticout:public easeelastic class CC_DLL EaseElasticInOu
T:public easeelastic//Jump buffer class Cc_dll Easebounce:public Actionease class Cc_dll Easebouncein:public Class Cc_dll Easebounceout:public easebounce class Cc_dll Easebounceinout:public easebounce//Back Shock buffer class Cc_dll Ease Backin:public Actionease class Cc_dll Easebackout:public actionease class Cc_dll Easebackinout:public ActionEase/ /Bezier Buffer class Cc_dll Easebezieraction:public actionease//Two buffer class Cc_dll Easequadraticactionin:public actionease cl Ass Cc_dll easequadraticActionout:public Actionease class Cc_dll easequadraticactioninout:public actionease//four times buffer class Cc_dll EaseQuarticAc Tionin:public Actionease class Cc_dll Easequarticactionout:public actionease class Cc_dll Easequarticactioninout:pub LIC actionease//five times Buffer class Cc_dll Easequinticactionin:public actionease class Cc_dll Easequinticactionout:public Act Ionease class Cc_dll Easequinticactioninout:public actionease//Loop buffer class Cc_dll Easecircleactionin:public ActionEas E Class Cc_dll Easecircleactionout:public actionease class Cc_dll easecircleactioninout:public ActionEase/cubic buffer class Cc_dll easecubicactionin:public actionease class Cc_dll Easecubicactionout:public actionease class CC_DLL EaseCubicActi
  Oninout:public Actionease

As you can see, the Actionease class provides subclasses of various buffering methods, each of which (except for Bezier buffers) is basically divided into three different transformations in the, out and inout phases.

Here are some chestnuts using actionease:

Create a sprite
auto sprite = sprite::create ("haha.jpg");

Add
this->addchild (sprite);

Create MoveTo action
Auto _moveto = Moveto::create (3.0,VEC2 (920,320));

Create sine buffer action
Auto _sineease = easesineinout::create (_moveto);

Perform action
sprite->runaction (_sineease);

Other types of buffering actions are used in the same way as the above example, except that the function names are different. Say I tried several kinds of, feel so many kinds of sports way really can not see out too big difference, anyway I think all looks like O (∩_∩) o haha ~.



Above.



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.