EasingDocument1
/**
* Copyright 883108 ( http://wonderfl.net/user/883108 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/b8Au
*/
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class EasingDocument1 extends Sprite {
private var _ball:Ball;
private var _easing:Number = .2;
private var _targetX:Number;
private var _targetY:Number;
public function EasingDocument1() {
init();
}
private function init():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
var tex:TextField = new TextField ;
addChild(tex);
tex.width = 450;
tex.x = tex.y = 10;
tex.multiline = true;
tex.text = 'クリックした位置にボールが徐々に近づき、その後はマウスストーカーになります。\n';
// ステージ上にスプライトを配置します。
addChild(_ball = new Ball);
_ball.x = stage.stageWidth / 2;
_ball.y = stage.stageHeight / 2;
// イベントハンドルを設定します。
stage.addEventListener(MouseEvent.CLICK, clickHandler);
}
private function clickHandler($event:MouseEvent):void{
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function enterFrameHandler($event:Event):void{
_targetX = mouseX;
_targetY = mouseY;
var distanceX:Number = _targetX - _ball.x;
var distanceY:Number = _targetY - _ball.y;
if(Math.abs(distanceX) < .5 && Math.abs(distanceY) < .5){
//trace(distanceX, distanceY)
_ball.x = _targetX;
_ball.y = _targetY;
//removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}else{
_ball.x = _ball.x + distanceX * _easing;
_ball.y = _ball.y + distanceY * _easing;
}
}
}
}
import flash.display.Sprite;
class Ball extends Sprite {
private var _radius:Number = 10;
function Ball(){
init();
}
private function init():void{
graphics.beginFill(0x000000);
graphics.lineStyle(0, 0x999999);
graphics.drawCircle(0, 0, _radius);
}
public function get radius():Number{
return _radius;
}
}