Flash bubble rebound effect

Source: Internet
Author: User

I haven't touched flash for a long time. Today I have reviewed as3.0 and made a rebound effect.
I was thinking about how to define different colors of bubbles so that we can make more beautiful effects, or make more progress 1. The bubbles and bubbles will rebound directly. If I haven't figured it out for a long time, let's do it first, updating when there are better solutions

Slice

 

As code

 

 

Package
{
Import flash. display. Sprite;
Import flash. Events. event;
Import flash. display. stagealign;
Import flash. display. stagescalemode;
Public class bubble extends Sprite
{
Public var count: Int = 6;
Public var bballs: array;
Public Function bubble ()
{
Init ();
}
Private function Init (): void
{
Stage. align = stagealign. Left;
Stage. scalemode = stagescalemode. no_scale;
Bols = new array;
For (VAR I = 0; I <= count; I ++ ){
VaR ball = new ball ();
// Ball. Alpha = math. Random ();

Ball. x = math. Random () * stage. stagewidth;
Ball. Y = math. Random () * stage. stageheight;
Ball. VX = math. Random () * 3-3;
Ball. Vy = math. Random () * 3-3;
Addchild (ball );
Bils. Push (ball );
}
Addeventlistener (event. enter_frame, onenterframe );

}
Private function onenterframe (Event: Event): void
{

VaR left = 0;
VaR Top = 0;
VaR Bottom = stage. stageheight;
VaR right = stage. stagewidth;

For (var I: Number = bils. Length-1; I> = 0; I --){

VaR ball = bils [I];
VaR radius: Number = ball. width/2;
Ball. x + = ball. VX;
Ball. Y + = ball. Vy;
If (ball. x> right-radius ){
Ball. x = right-radius;
Ball. VX * =-1;
}
If (ball. x <radius ){
Ball. x = radius;
Ball. VX * =-1;
}
If (ball. Y> bottom-radius ){
Ball. Y = bottom-radius;
Ball. Vy * =-1;
}
If (ball. Y <radius ){
Ball. Y = radius;
Ball. Vy * =-1;
}

}

}

}

}

 

File Download
Flash bounce .rar

 

 

 

 

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.