所以我刚刚开始尝试从 AS2 合并到 AS3,但事情已经不像逻辑上应该的那样了。我正在尝试制作一个简单的基于时间的粒子系统,只需一个发光的球影片剪辑就可以制作出烟花效果。有一个 Main 类和一个名为 Ball 的发光球类。问题是当我将生成圆圈的 Main 类中的 addEventListener 更改为: stage.addEventListener(MouseEvent.CLICK...) 由于某种原因,圆圈并非都从同一点(在中心)开始,并且我等待点击的时间越长,它们产生的距离就越远......我到底做错了什么?
主类:
package {
import flash.display.MovieClip;
import flash.events.*;
public class Main extends MovieClip {
public function Main() {
addEventListener(Event.ADDED_TO_STAGE, downed);
}
private function downed(event:Event){
for(var i:int = 0; i < 50; i++){
var a:Ball = new Ball(275, 200, randomSpeed(), randomSpeed());
addChild(a);
}
}
private function randomSpeed():int{
var speed:int = Math.random()*150;
if(Math.random() > .5){
speed *= -1;
}
return speed;
}
}
}
球类:
package {
import flash.display.*;
import flash.events.*;
import flash.utils.getTimer;
public class Ball extends MovieClip {
private var speedX, speedY:Number;
private var lastTime:int;
private var gravity:int = 3.5;
public function Ball(x:int, y:int, dx:int, dy:int):void {
this.x = x;
this.y = y;
speedX = dx;
speedY = dy;
lastTime -= getTimer();
this.addEventListener(Event.ENTER_FRAME, moveBall);
}
private function moveBall(event:Event){
var timePassed:int = getTimer()-lastTime;
lastTime += timePassed;
this.x += (speedX*timePassed)/1000;
this.y += (speedY*timePassed)/1000;
speedY += gravity;
}
}
}