Pointの練習 其の弐
マウスを近づけたらmaruが回る。150px離れると止まる。
/**
* Copyright argon ( http://wonderfl.net/user/argon )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jpSK
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
/**
* ...
* @author I am Afro Boy ヾ(。`Д´。)ノ
*/
public class Main extends Sprite
{
private var maru:Draw;
private var pt0:Point;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
maru = new Draw();
addChild(maru);
pt0 = new Point(200, 300);
maru.x = pt0.x; maru.y = pt0.y;
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
}
private function onEnterFrameHandler(e:Event):void
{
var maruPt:Point = new Point(maru.x, maru.y);
var mousePt:Point = new Point(stage.mouseX, stage.mouseY);
var distance:Number = Point.distance(maruPt, mousePt);
if (distance < 150)
{
maru.rotation += 5;
}
}
}
}
import flash.display.*;
class Draw extends Sprite
{
private var sp:Sprite;
public function Draw()
{
sp = new Sprite();
addChild(sp);
sp.graphics.lineStyle(3, 0x000000);
sp.graphics.moveTo(0, 0);
sp.graphics.lineTo(30, 0);
sp.graphics.drawCircle(0, 0, 30);
}
}