Flash make beautiful scenery animation

Source: Internet
Author: User
Tags define window

Today went to a flash bar forum, found this good tutorial, for everyone to publish!

  Demo effect

Click here to download the source file

In fact, there is no production process, where I put the mountains, the sea, the sky, clouds, and headmistress, and so all made into components, through the call library in the movie clips, to achieve layout and animation. Here's the script.

OnLoad = function () {
Load event, full screen playback, where if Fullscreen is false, the Full-screen playback is canceled
Fscommand ("fullscreen", true);
Define variable num and assign values to set the number of sailing boats. This is set to 10
num = 10;
Call the component Hai in the library, actually here I created a movie clip and set the link properties, the link name is Hai
_root.attachmovie ("Hai", "Hai", 19);
These are the positions of the Hai component in the scene, where the Hai is the component of the sea,
This can change the parameters according to the layout of your picture,
I'm here by calling the width and height of the scene and then dividing it into a
_root.hai._x = STAGE.WIDTH/2;
_root.hai._y = stage.height/1.4;
Call the movie clip in the Library Shan, which is the mountain in the picture, set the parameters according to the screen layout
_root.attachmovie ("Shan", "Shan", 17);
_root.shan._x = STAGE.WIDTH/2;
_root.shan._y = 88;
This is the Sky component Tian, same as above, do not elaborate, we should pay attention to the level of the layer here,
Here I have fixed the layer of the stationary element and set it to prime, where the 17,19 are primes,
This will still have considerable benefits for future settings,
Otherwise it is easy to repeat the hierarchy, which can cause the script to run incorrectly
_root.attachmovie ("Tian", "Tian", 0);
_root.tian._x = STAGE.WIDTH/2;
_root.tian._y = 50;
This script is set to Headmistress, that is, the black cloth that everybody sees, because to block all the animation process,
So the level of the set is also the highest, 1000, so as to ensure that at the top, 1000 layers enough
In fact, headmistress is also a production process, I would like to be here before I published such a tutorial and articles, we carefully look for?
_root.attachmovie ("Zedang", "Zedang", 1000);
_root.zedang._x = STAGE.WIDTH/2;
_root.zedang._y = STAGE.HEIGHT/2;
Copy the sailing boat and arrange the position of the sailing boat randomly, but here I take a fixed + random arrangement in the direction of vertical (y).
x direction I was taken by random arrangement, size through script _xscale = _yscale=math.floor (Math.random () *80+20);
To control, this parameter can be set according to your intention, in general, 100 is to maintain the original size, greater than 100 is magnified,
Less than 100 is reduced, and support for negative scaling is actually reversed, where replication takes A for loop
for (var i = 0; i<num; i++) {
Set the speed of the cloud to set a different speed for each cloud
this["Yusu" +i] = (i+10)/15;
Call the Cloud Component Yun in the library and set the depth (level of the layer) I used an even arrangement
_root.attachmovie ("Yun", "Yun" +i, 2* (i+1));
With (this["Yun" +i]) {
Here is the position and size of the cloud, which is a fixed plus random method, which is just the initial position
_x = Math.floor (Math.random () *stage.width);
_y = 30+math.floor (Math.random () *100);
_xscale = _yscale=math.floor (Math.random () *80+20);
}
The script here is to dynamically set the speed of a sailboat, setting a different speed for each sailboat, so that there is a sense of rapidity.
this["su" +i] = (i+1)/2;
Here is the replica of the sailing boat and randomly distributed sailing position, the size of the ship is also taken far smaller near the big, so more suitable for our vision
_y = 149+ (20*i); Through this script, the sailboat can be distributed within the sea element range.
Attachmovie ("Boat", "MC" +i, (i+1) *30);
With (this["MC" +i]) {
_x = Math.floor (Math.random () *stage.width);
_y = 149+ (20*i);
_xscale = _yscale= (i+1) *num;
}
}
};
Let the onload () event run once, otherwise easy to cause the script can not run, no effect, this is the problem that is easy to appear in 2004
OnLoad ();
Okay, go into the frame-rate event, start the animation phase, let's animate it,
This.onenterframe = function () {
for (var i = 0; i<num; i++) {
With (this["Yun" +i]) {
When the cloud moves over the width of the scene, it returns to the left, which ensures that the cloud repeats itself because, given the size of the movie clip, it sets the position to return to half the size of the movie clip on the left.
if (_X&GT;STAGE.WIDTH+_WIDTH/2) {
_x =-_WIDTH/2;
}
Define the step speed of the cloud, that is, the distance each frame runs, where it is dynamically given the speed that we set up in the front
_x + + this["Yusu" +i];
}
Here is the setting of the sailing speed and the conditions that appear when more than the principle of the cloud is the same as the
With (this["MC" +i]) {
if (_X&GT;STAGE.WIDTH+_WIDTH/2) {
_x =-_WIDTH/2;
}
_x + + this["su" +i];
}
}
};
OK, the script completes, now everybody can ctrl+enter to look at own work, everybody feels is not uses the foot to realize the layout, very has the achievement feeling?
Script Note: Black market Magic Flag



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.