AS 会飞的小蜜蜂,随机线性正弦函数。
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class Bobbing extends MovieClip
{
private var mi:Mi;
private var angelX:Number = 0;
private var angelY:Number = 0;
private var centerX:Number = 200;
private var centerY:Number = 200;
private var range:Number = 150;
private var xspeed:Number=.05;
private var yspeed:Number=.02;
public function Bobbing()
{
init();
}
private function init()
{
mi=new Mi();
addChild(mi);
mi.x = 0
mi.y = stage.stageHeight / 2;
addEventListener(Event.ENTER_FRAME,hs);
}
public function hs(e)
{
mi.x=centerX+Math.sin(angelX)*range;
mi.y=centerY+Math.sin(angelY)*range;
angelX+=xspeed;
angelY+=yspeed;
}
}
}