Using as to control the tilt property of MC

Source: Internet
Author: User
Tags pow sin
Control

In Flash, the tilt properties of the MC can be set by hand. In Flash, tilt is an important aspect of achieving 3D effects. But there is no code to skew the property, although the code that simulates 3D now has a lot of people doing it, But at present, it is usually confined to the simulation of the coordinate point. For objects, the simple 3D effect of a bitmap, even if just a tilt, as has not been able to do. In order to solve this problem (the problem, a user has also asked the classic), I spent nearly a week to study: less nonsense, or to the point of it.
11 Simple experiments:

In Flash, draw a rectangle (do not turn into a component), the rectangle is then rotated slightly. Then you zoom in the horizontal direction of the rotated rectangle, and you see that the moment line is actually tilted. Therefore, using the _xscale and _rotation properties of as as in can make the MC dynamically tilt.

2 Apply this test to as

You might as well write a code to try:
Make an MC (the more complex the more likely the effect will be)
Write code into MC:

Onclipevent (enterframe) {
_rotation=30;
_xscale=30;
}

Test, there is no tilt effect, a careful look will find that after the MC rotation, the coordinates of the scaling also follow the rotation.
What a pity!

Is there no way out? The answer is NO! Since the MC rotation, the scaling coordinates followed by rotation, then, we will turn the MC of the rotation to MC, then there are two coordinate systems? can not achieve the effect of small test? The author may be more stupid, this small problem has also been stuck for 3 minutes. To get to the point, Let's go on. Empty the code for the MC just now, name it MYMC, and convert it to a movie clip. Enter the code for the converted movie clip:

Onclipevent (load) {
Mymc._rotation=30
_xscale=30
}

Test again, tilt the effect out!
I think this can be done, want to set up their own dynamic MC tilt 30 degrees, but found that the above code, although it is tilted, but the tilt is not 30 degrees, above two properties and tilt properties of the author is a more complex mathematical relationship. The author spent nearly a week studying the relationship, albeit a little dizzy, But eventually it came out. Replace the above code with the following:

Onclipevent (load) {
function Setskewx (Anglex) {
var angx = anglex%360;
var tx = 1/math.tan (angx* (math.pi/180));
var Alfax = (Math.tan (angx* (math.pi/180)) = = 0)? MATH.PI/2: (Math.asin (MATH.SQRT (tx*tx+1)-1)/tx));
Mymc._rotation =-45;
_xscale = 100*math.sin (Alfax);
Mymc._xscale = 100/math.sqrt (1/2* (Math.pow (Math.sin (Alfax), 2) +1));
Mymc._yscale = 100/math.sqrt (1/2* (Math.pow (Math.sin (Alfax), 2) +1));
_rotation = Math.atan (1/math.sin (Alfax))/(math.pi/180);
if (Math.Cos (angx* (math.pi/180)) <0) {
Mymc._yscale *=-1;
}
}
function Setskew (Anglex, Angley) {
Setskewx (Anglex-angley);
_rotation + = Angley;
}
}
Onclipevent (enterframe) {
an = (an+1)%360;
Setskew (an,0)
}

I see the effect.

From the previous simple test, to the written code, it's a hard thing to do. But anyway, the code is written, and I hope that you can learn something from it. As to how the code from the simple test code to the above has been introduced, what is the meaning of the statement, I will explain to you in this period.



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.