我试图创建一个不断扩大的圈子有几个原因。对于测试平台,我正在使用 actionscript 为其开发起点。
这是我到目前为止的代码:
编辑
更新代码 13.39 GMT+1 - 再次更新代码
更新代码 14.54 GMT+1 - 更新代码,现在运行非常流畅,感谢 Vesper 的帮助
主文件
package
{
import flash.display.MovieClip;
import flash.events.Event;
import Wavelet;
import flash.geom.Point;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.utils.getTimer;
public class Main extends MovieClip
{
var startColor:Number = 0x00AA00;
var particleBitmapdata:BitmapData;
var m_temptimer:int;
private var myVector:Vector.<Wavelet> = new Vector.<Wavelet>();
public function Main()
{
// constructor code
addEventListener(Event.ADDED_TO_STAGE, init);
addEventListener(Event.ENTER_FRAME, update);
}
public function init(evt:Event)
{
particleBitmapdata = new BitmapData(3,3,false, startColor);
var myTimer:Timer = new Timer(100, 0);
myTimer.addEventListener(TimerEvent.TIMER, run);
myTimer.start();
}
public function run(tevt:TimerEvent)
{
for(var i:int=0; i < 360; i+=1)
{
myVector.push(new Wavelet(3, 1, i, startColor,particleBitmapdata));
myVector[myVector.length-1].x = stage.stageWidth/2;
myVector[myVector.length-1].y = stage.stageHeight/2;
addChild(myVector[myVector.length-1]);
}
}
public function update(evt:Event)
{
var time:int = getTimer();
var dt:Number = (time - m_temptimer) * 0.001;
m_temptimer = time;
for(var i:int=0; i < myVector.length-1; i++)
{
var w:Wavelet = myVector[i];
if(w.x > stage.stageWidth || w.x < 0 )
{
removeChild(myVector[i]);
myVector[i] = null;
myVector.splice(i,1);
}
if(w.y > stage.stageHeight || w.y < 0 )
{
removeChild(myVector[i]);
myVector[i] = null;
myVector.splice(i,1);
}
}
for(var j:int=0; j < myVector.length; j++)
{
myVector[j].update(dt);
}
}
}
}
小波.as
package
{
import flash.display.*;
import flash.events.*;
import flash.geom.Point;
import flash.filters.*;
import flash.geom.*;
public class Wavelet extends Bitmap
{
private var m_velocity:Number;
private var m_angle:Number;
private var m_radius:Number;
private var m_bmd:BitmapData;
private var m_color=0x0000FF;
private var m_angleX,m_angleY;
public function getAngle():Number
{
return m_angle;
}
public function getVelocity():Number
{
return m_velocity;
}
public function setVelocity(input:Number)
{
m_velocity = input;
}
public function Wavelet(radius:int, velocity:Number, angle:Number, color:Number, bitmapData:BitmapData)
{
// constructor code
m_radius = radius;
m_angle = angle * Math.PI / 180 ;
m_velocity = velocity;
m_angleX = Math.cos(angle);
m_angleY = Math.sin(angle);
m_color = color;
m_bmd = bitmapData;
this.bitmapData = m_bmd;
}
public function update(dt:Number)
{
this.x+= m_angleX * m_velocity;
this.y+= m_angleY * m_velocity;
m_velocity+=dt;
}
}
}
无论如何,我从中得到的表现非常缓慢。我不想作为一个整体创建一个扩大的圆圈,我需要像素来计算它们何时与墙壁和物体碰撞,以使它们改变方向。
无论如何,您可以制作一个性能更好的扩展圈吗?