PDA

View Full Version : Detecting Distance


Ingenieurs
06-01-2008, 09:22 PM
Hello.

Imagine you have a circle in the centre of the stage, it's a movie clip. You want the circle to grow depending upon how close the mouse cursor is to it, from within a radius of say 200 pixels. I can think of lots of bodged ways to do this, but wondered if there was a nice clean way? :)

Any help would be appreciated, A.

lordofduct
06-01-2008, 10:01 PM
var circle:Sprite = new Sprite();
circle.x = stage.stageWidth / 2;
circle.y = stage.stageHeight / 2;
addChild(circle);

addEventListener(Event.ENTER_FRAME, update);

function update(e:Event):void
{
var xi:Number = mouseX - circle.x;
var yi:Number = mouseY - circle.y;
var r:Number = Math.sqrt( xi * xi + yi * yi );

circle.graphics.clear();
circle.graphics.lineStyle(1, 0x000000);
circle.graphics.drawCircle(0,0,r);
}


What do you mean by within 200 pixels?

Ingenieurs
06-02-2008, 06:37 AM
Thanks. I mean that the circle would do nothing until you get to within 200 pixels of it, then it starts to grow. Outside of that 200 pixel boundary, nothing happens.