Flash实例教程:AS3.0实现逼真喷泉效果
2009-04-20 12:02:16 来源:WEB开发网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;
}
}
}
- ››FLASH不等于运算符!=的使用实例
- ››FLASH不全等运算符!==
- ››FLASH字符串分隔符运算符
- ››FLASH% 模运算符
- ››Flash+、++、+= 加法运算符
- ››Flash, 逗号运算符
- ››flash中的-、--、-=减法运算符
- ››Flash的-Infinity 常数、.点运算符、/ 除法运算符...
- ››Flash两种注释方法/*..*/ 和// 注释行分隔符运算符...
- ››Flash的/=除法赋值运算符、=赋值运算符、== 等于运...
- ››Flash之?: 条件运算符、^ 按位 XOR 运算符、^= 按...
- ››Flash的_framesloaded代码示例
更多精彩
赞助商链接