マウスに追従するSprite

This movie requires Flash Player 9

円のローカル座標とマウスの位置関係から。

//半径10pxの黒丸を描写
var circle:Sprite = new Sprite();
circle.graphics.beginFill(0x000000);
circle.graphics.drawCircle(15,20,10);
addChild(circle);

var cx:int;
var cy:int;

//マウスの後を追いかける(マウスとローカル座標の距離を詰める)
circle.addEventListener(Event.ENTER_FRAME, moveCircle);

 function moveCircle(event:Event):void {

  cx = circle.mouseX;
  cx = circle.mouseY;

  circle.x += cx/5;
  circle.y += cy/5;
}

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*