WEB开发网
开发学院图形图像Flash Flash实例教程:AS3.0实现逼真喷泉效果 阅读

Flash实例教程:AS3.0实现逼真喷泉效果

 2009-04-20 12:02:16 来源:WEB开发网   
核心提示: ball.x +=ball["vx"]; ball.y +=ball["vy"]; 接下来的是看水珠是否超出了舞台,如果超出了舞台,Flash实例教程:AS3.0实现逼真喷泉效果(3),则将水珠重新定位到喷射口,并将速度向量设为初始状态

ball.x +=ball["vx"];
ball.y +=ball["vy"];

接下来的是看水珠是否超出了舞台,如果超出了舞台,则将水珠重新定位到喷射口,并将速度向量设为初始状态。

if (ball.x - ball.width/2> stage.stageWidth ||
ball.x + ball.width/2 < 0 ||
ball.y - ball.width/2 > stage.stageHeight ||
ball.y + ball.width/2 < 0) {
ball.x = 260;
ball.y = 200;
ball["vx"]= Math.random() * 2 - 1;
ball["vy"] = Math.random() * -10 - 10;

完整代码:

var count:int = 500;
var zl:Number = 0.5;
var balls:Array;
balls = new Array();
for (var i:int = 0; i < count; i++) {
var ball:pall = new pall();
ball.x = 260;
ball.y = 200;
ball["vx"]= Math.random() * 2 - 1;
ball["vy"] = Math.random() * -10 - 10;
addChild(ball);
balls.push(ball);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void {
for (var i:Number = 0; i < balls.length; i++) {
var ball:pall = pall(balls[i]);
ball["vy"] += zl;
ball.x +=ball["vx"];
ball.y +=ball["vy"];
if (ball.x - ball.width/2> stage.stageWidth ||
ball.x + ball.width/2 < 0 ||
ball.y - ball.width/2 > stage.stageHeight ||
ball.y + ball.width/2 < 0) {
ball.x = 260;
ball.y = 200;
ball["vx"]= Math.random() * 2 - 1;
ball["vy"] = Math.random() * -10 - 10;
}
}
}

上一页  1 2 3 

Tags:Flash 实例 教程

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接