Code _flash as to control the tilt property of the MC

Source: Internet
Author: User
Tags pow sin
In Flash, the tilt properties of the MC can be set manually. In Flash, tilt is an important aspect of achieving 3D effects.
But as there is no skew attribute code, although the simulation of 3D code has been a lot of people to do it, but now is generally limited to the simulation of the coordinates. For objects, the simple 3D effect of bitmaps, even if one tilt, as has not yet been done.
In order to solve this problem (this problem, a classic user has also asked), I spent nearly a week to study:
Cut the crap, or turn to the point.
11 Simple experiments:
In Flash, draw a rectangle (do not turn into a component), and then rotate the rectangle slightly.
Then you zoom in the horizontal direction of the rotating rectangle and you see that the moment line is actually tilted.
Therefore, using the _xscale and _rotation properties of as as in can let 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? The answer is NO!
Since the MC rotation, the scaling coordinates followed by rotation, then, we will turn the MC to the rotation, then there are two coordinate systems? can not achieve the effect of small test?
The author may be more stupid, this small problem has been stuck for 3 minutes.
Let's go on with the talk.
Just empty the code for the MC, 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 own dynamic set of MC tilt 30 degrees, but found that the above code, although it is tilted, but the tilt is not 30 degrees, the above two properties and tilt attribute also exists for the author is more complex mathematical relationship.
The author spent nearly a week studying the relationship, although a little dizzy, but eventually to get 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 front of the simple test, to write this code, is extremely difficult. But anyway, the code is written, and I hope to get you to learn something.
As for the introduction of the code from the simple test code to the above, what is the meaning of the statement, I will give you an explanation during 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.