Flash气泡回弹效果
好久没有碰过Flash了,今天温习一下AS3.0,做了一个回弹效果,气泡回弹
本想着怎么可以定义气泡的不同颜色,这样可以做出更绚丽的效果,或者更进步一,气泡和气泡直接回弹,想了老半天没有想出来,就先这样,等有更好的方案时候在更新
效果图片
as代码
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 balls:Array;
public function bubble ()
{
init ();
}
private function init ():void
{
stage.align = StageAlign.LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
balls = 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);
balls.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 = balls.length - 1; i >= 0; i--) {
var ball = balls[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;
}
}
}
}
}
{
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 balls:Array;
public function bubble ()
{
init ();
}
private function init ():void
{
stage.align = StageAlign.LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
balls = 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);
balls.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 = balls.length - 1; i >= 0; i--) {
var ball = balls[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;
}
}
}
}
}
文件下载
Flash回弹.rar
个人签名:天行健,君子以自强不息