曲線を描く運動
/**
* Copyright _wonder ( http://wonderfl.net/user/_wonder )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/1Zf1
*/
// forked from _wonder's 加速してから減速する運動
// forked from _wonder's 減速する運動
// forked from _wonder's 加速する運動
// forked from _wonder's 等速運動
// forked from _wonder's base
package {
import flash.display.Sprite;
import flash.events.Event;
public class FlashTest extends Sprite {
private var ball:Ball;
private var target:Ball;
private var ax:Number = 0.005;//加速度
private var ay:Number = 0.005;
private var per:Number = 0.005;//加速度を増やす
public function FlashTest() {
target = new Ball(20);
target.x = stage.stageWidth - 80;
target.y = stage.stageHeight - 20;
target.alpha = 0.3;
addChild( target );
ball = new Ball(20);
ball.x = 20;
ball.y = stage.stageHeight / 2;
addChild( ball );
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void {
if( target.y > 80 ){
target.y -= 10;
}
if( ball.x < target.x ){
var dx:Number = target.x - ball.x;
var dy:Number = target.y - ball.y;
ax += per;
ay += per;
ball.x += dx * ax;
ball.y += dy * ay;
}
}
}
}
import flash.display.Sprite;
class Ball extends Sprite {
public var radius:Number;
public var color:uint;
public function Ball(radius:Number=40, color:uint=0Xff0000){
this.radius = radius;
this.color = color;
init();
}
public function init():void {
graphics.beginFill(color);
graphics.drawCircle(0, 0, radius);
graphics.endFill();
}
}