About the ccactionease in Cococs (bottom)

Source: Internet
Author: User

The actions we described above are mainly used to change the execution speed of internal actions, and the following actions are mainly used to increase the performance of the action, can be seen as a simple effect.

) Cceasebackin
1 void Cceasebackin::update (Cctime time)
2 {
3 Cctime overshoot = 1.70158f;
4 m_pother->update (Time * time * ((overshoot + 1) * time-overshoot));
5}

We have done many times before, we must all be pro, deduce a formula:
S (t) = (overshoot+1) *t^3-overshoot*t^2 t∈[0,1]
V (t) =s ' (t) =3* (overshoot+1) *t^2-2*overshoot*t t∈[0,1]
A (t) =v ' (t) =6* (overshoot+1) *t-2*overshoot t∈[0,1]

To draw a function image in Geogebra:

Take a look at the blue curve in the picture. After the action is performed, the sprite first moves in the negative direction of the y-axis, moving approximately to the y=-0.1 and starting to move in the normal direction of movement towards the point G.

It sounds a little complicated, so let me tell you a story. The former martial scholar, there is a code 1.70158 people also come to participate, he put the arrow on the bow, and then pull back, but the strength is too small, can only pull the bow 10%, hand a slippery, the arrow flew out, did not think the center of the bull's Eye point g (quirks), the martial champion.

The story is finished, then you must have heard, this cceasebackin is actually a bow archery process.

That this code 1.70158 of the martial champion is the bow pulled out 10%? Interested friends can follow me to calculate a count.

The red curve in the figure represents speed, so long as it is below the x-axis, it means that the martial scholar is pulling the bow. If the red curve is above the x-axis, it means that he has put the arrows out. So the intersection of the red curve and the x-axis is the moment he loosens his hand. Over point B to do the x-axis perpendicular, the blue curve and the C-point, the C-point ordinate is the degree of the martial scholar pull the bow.

In this process, we calculate that the horizontal axis of point B is:
b.x=2*overshoot/(overshoot+1) =0.419897
c.x=0.419897
Bring this value inside the s (t) function, resulting in:
C.y=s (c.x) =-0.1

Because the main purpose of this action is to achieve special effects, so its speed is not very important, the need for friends to calculate the red curve in the [0,1] range of extrema.

One) cceasebackout
1 void Cceasebackout::update (Cctime time)
2 {
3 Cctime overshoot = 1.70158f;
4 time = time-1;
5 m_pother->update (Time * time * ((overshoot + 1) * time + Overshoot) + 1);
6}

The action Cceasebackin inverted play is cceasebackout, please look at the picture:

Cceasebackinout)

Bug #961: Fix mad behaviour in second stage of Cceasebackinout

In the previous version of cocos2d-1.0.1-x-0.12.0, the behavior of the Cceasebackinout action was somewhat problematic, if you are still using the old version, go ahead and upgrade it.

1 void Cceasebackinout::update (Cctime time)
2 {
3 Cctime overshoot = 1.70158f * 1.525f;

5 Time = time * 2;
6 if (Time < 1)
7 {
8 M_pother->update ((Time * time * ((overshoot + 1) * time-overshoot))/2);
9 }
Ten Else
Each {
Time = time-2;
M_pother->update ((Time * time * ((overshoot + 1) * time + Overshoot))/2 + 1);
+ }
15}

See this code of you, may be extremely confused. This confusion is not inexplicable, since you see overshoot first eye, this seed has been planted in your heart.

Why does 1.70158 equal a 10% "bounce"?
What does 1.70158 mean?
What the hell is 1.525 here?

It seems that if I don't make these clear, today is not going to work.

Let me just say a few words briefly. As for right and wrong, you can polish your eyes.

Do you remember the process of calculating c.y above? If we don't take the value of overshoot, we deduce it again.

c.x=2*overshoot/(overshoot+1)
C.y=s (c.x)
C.y= (2*overshoot/(overshoot+1)) ^2* ((overshoot+1) * (2*overshoot/(overshoot+1))-overshoot)
C.y= (2*overshoot/(overshoot+1)) ^2* (2*overshoot/3-overshoot)
C.y= (2*overshoot/(overshoot+1)) ^2* (-OVERSHOOT/3)
c.y=-(4*overshoot^3)/(27* (overshoot+1) ^2)

Because we want to find out how much the 10% corresponds to the overshoot, and C.Y is below the x-axis, so we make c.y=-0.1.

c.y=-0.1
-(4*OVERSHOOT^3)/(27* (overshoot+1) ^2) =-1/10
40*overshoot^3=27* (overshoot+1) ^2
40*overshoot^3-27*overshoot^2-54*overshoot-27=0

The following is a purely mathematical problem, solving a three-time equation.

After a series of operations, it is concluded that the three-dimensional equation has a real roots and two conjugate complex roots. This real roots is the value we want--1.70154. Yes, you're right, I counted 1.70154. I don't know why it's not 1.70158, is it a magical error?

Let's take a look at how this 1.525 came from.

And Cceasebackinout is actually the image of Cceasebackin and cceasebackout reduced to half, and then put into [0,0.5] and [0.5,1] in the interval. Because it is reduced to half, so we need to recalculate the value of the overshoot, so that the original pop-up 10% to 20%, so that the size of the popup to maintain the same amplitude.

Make c.y=-0.2, get a three-time equation:
20*overshoot^3-27*overshoot^2-54*overshoot-27=0

The solution overshoot has a value of 2.59239, which is exactly 1.52355 times times the original 1.70154.

Oops, embarrassed big, finally calculated out two numbers, with the code of people use is not the same.

What the hell is going on here? is the problem of error? Or is my algorithm wrong? Wait for the expert to guide.

Cceasebounceout)

This time we want to adjust the order slightly, first to introduce the Cceasebounceout action, because Cceasebouncein is according to its definition of the mirror, so cceasebounceout is the realization of the ontology.

1 void Cceasebounceout::update (Cctime time)
2 {
3 Cctime NewT = bouncetime (time);
4 m_pother->update (NewT);
5}

This time the transformation function is independent, let's go in and see.

1 cctime cceasebounce::bouncetime (cctime time)
2 {
3 if (Time < 1/2.75)
4 {
5 Return 7.5625f * time * time;
6
7 if (Time < 2/2.75)
8 {
9 Time- = 1.5f/2.75f;
return 7.5625f * time * time + 0.75f;
One } else
if (Time < 2.5/2.75)
{
+ Time- = 2.25f/2.75f;
return 7.5625f * time * time + 0.9375f;
+ }

Time- = 2.625f/2.75f;
return 7.5625f * time * time + 0.984375f;
20}

This time to change the formula 4 times, we first draw it out.

Perhaps you have not seen what this is, in order for everyone to see it, we have it in accordance with y=0.5 to do an axisymmetric image.

Do you see it now?

By the way, the Cceasebounceout action is the bouncing motion of the simulated ball falling.

Here the small ball played 3 times altogether. After landing for the 3rd time, the ball finally did not have enough strength to jump up again.

Cceasebouncein)

Before we said Cceasebouncein action is in accordance with the definition of cceasebounceout image.

1 void Cceasebouncein::update (Cctime time)
2 {
3 Cctime NewT = 1-bouncetime (1-time);
4 m_pother->update (NewT);
5}

The mirror is centered symmetrically by the point (0.5,0.5).

What does it look like to play a small ball upside down? Or imagine the process of beating up a basketball that is still on the ground.

Cceasebounceinout)
1 void Cceasebounceinout::update (Cctime time)
2 {
3 Cctime NewT = 0;
4 if (Time < 0.5f)
5 {
6 Time = time * 2;
7 NewT = (1-bouncetime (1-time)) * 0.5f;
8 }
9 Else
Ten {
One NewT = bouncetime (Time * 2-1) * 0.5f + 0.5f;
-- }

m_pother->update (NewT);
15}

The implementation of Cceasexxxxinout action is always the most boring, nothing more than to reduce the cceasexxxxin and cceasexxxxout half, and then spell together.

Summary

Today, a total of two types of action are introduced, the first type is in the simulation of ejection movement, the second type is in the simulation of the ball drop and other bouncing motion. They are not primarily intended to modify the speed of internal movements, but to add special display effects to them.

Due to the limitation of space, Ease elastic class action will be put on the next introduction.

If you go to the reference manual, you'll see a warning in the description of these three types of actions:

This action doesn ' t use a bijective fucntion. The Actions like Sequence might has an unexpected result when the used with the this action.

So do not pass actions such as ccsequence to them as arguments, but you can pass them to ccsequence to create an action queue.

About the ccactionease in Cococs (bottom)

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.