Flash Game production: Click on the ball to play

Source: Internet
Author: User
Tags vars
The new year will come, here first to everyone to worship an early years, I wish you all in the rooster, the level of flash high. OK, now let's get to the point where we'll look at the effect.


   source file Download (Zip compressed file, 6K).

In addition, you can take a look at a once very popular product game: "It's a man, 100."

This is an extension of the simple elastic effect. The main body is basically all used as to achieve. Here is a brief explanation of the production process.

1. In Flash, a new MC, on this MC, built three layers to put round, button, as well as command. As shown in the figure:

Here, the As command is:

Stop ();


2. Go back to the main scene and add the As command on the first frame.

_root.createemptymovieclip ("Ball", 69);

Create an empty MC named Ball

Ball.linestyle (0xFFFFFF, 100);

Set ball line style is 60 thick, white, alpha is 100

Ball.lineto (1, 0);

Draws a line from the current drawing position to (x, y) using the current line style

VARs = new Array ("XSpeed", "Yspeed", "Leftedge", "Rightedge", "Bottomedge", "Gravity", "friction", "bounce", "Widthball", "Heightball", "Maxaffiche", "forcedribble", 6, 0, -30, (stage.width) + (_ROOT.BALL._WIDTH/4), (Stage.height) + (_ ROOT.BALL._WIDTH/4), 2.4, 0.982, 0.7, _ROOT.BALL._WIDTH/2, _ROOT.BALL._HEIGHT/2, 10, 22);

Set up an array

for (i=0; i< (VARS.LENGTH/2); i++) {
This[vars[i]] = vars[i+ (VARS.LENGTH/2)];
}

The value of the initial array

//-----------------------------------------

Ball when clicked, change the value of the xspeed,yspeed in the array

ball.onpress = function () {
_root.xspeed-= (_root._xmouse-this._x)/2;
_root.yspeed =-_root.forcedribble;
};
//---------------------------------------

Set the ball bounce,
Ball.onenterframe = function () {
this._x = This._x+xspeed;
this._y = This._y+yspeed;
if (This._x+widthball>rightedge | | this._x-widthball
XSpeed =-xspeed*bounce;
this._x = (This._x+widthball>rightedge)? (Rightedge-widthball): (Leftedge+widthball);
}
if (This._y+heightball>bottomedge) {
Yspeed =-yspeed*bounce;
this._y = Bottomedge-heightball;
}
Yspeed = (yspeed*friction) +gravity;
XSpeed = xspeed*friction;
};



Note: This example is for study use only, please do not use for commercial use!

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.