Commonly used formula in Flash as3

Source: Internet
Author: User

Easing formula:

Sprite. x + = (targetx-Sprite. X) * easing; // easing is the easing coefficient variable.

Sprite. Y + = (targety-Sprite. Y) * easing;

Elastic formula:

VX + = (targetx-Sprite. X) * spring; // spring is the elastic coefficient.

Vy + = (targety-Sprite. Y) * spring;

Sprite. x + = (VX * = friction); // friction indicates Friction

Sprite. Y + = (Vy * = friction );

Offset elastic formula:

VaR DX: Number = Sprite. X-fixedx;

VaR DY: Number = Sprite. Y-fixedy;

VaR angle: Number = math. atan2 (dy, dx );

VaR targetx: Number = fixedx + math. Cos (angle) * springlength;

VaR targety: Number = fixedx + math. Sin (angle) * springlength;

Rotate to the mouse (or to a certain point)

DX = mousex-Sprite. X;

DY = mousey-Sprite. Y;

Sprite. Rotation = math. atan2 (dy, dx) * 180/Math. Pi;

Waveform motion:

Public Function onenterframe1 (Event: Event): void {

Ball. Y = centerscale + math. Sin (angle) * range;

Angle + = speed;

}

Heartbeat:

Public Function onenterframe1 (Event: Event): void {

Ball. scalex = centerscale + math. Sin (angle) * range;

Ball. scaley = centerscale + math. Sin (angle) * range;

Angle + = speed;

}

Center rotation:

Public Function onenterframe (Event: Event): void {

Ball. x = centerx + math. Cos (angle) * radius;

Ball. Y = centery + math. Sin (angle) * radius;

Angle + = speed;

}

Elliptical rotation:

Public Function onenterframe (Event: Event): void {

Ball. x = centerx + math. Cos (angle) * radiusx;

Ball. Y = centery + math. Sin (angle) * radiusy;

Angle + = speed;

}

The color operation returns the transparent value:

VaR T: uint = 0x77ff8877

VaR S: uint = 0xff000000

VaR H: uint = T & S

VaR M: uint = H >>> 24

Trace (m)

Convert to decimal:

Trace (hexvalue );

Convert decimal to hexadecimal:

Decimalvalue. tostring (16)

Color extraction:

Red = color24> 16;

Green = color24> 8 & 0xff;

Blue = color24 & 0xff;

Alpha = color32> 24;

Red = color32> 16 & 0xff;

Green = color32> 8 & 0xff;

Blue = color0000& 0xff;

Calculated by bit to obtain the color value:

Color24 = red <16 | green <8 | blue;

Color32 = Alpha <24 | red <16 | green <8 | blue;

Curve over control point:

// XT, yt is the point you want to draw through

// X0, y0 and X2, Y2 are the end points of the curve

X1 = XT * 2-(x0 + x2)/2;

Y1 = yt * 2-(y0 + y2)/2;

MoveTo (x0, y0 );

Curveto (x1, Y1, X2, Y2 );

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.