;

PDA

Click to See Complete Forum and Search --> : can i detect mouse direction?


albisher
08-04-2007, 06:39 AM
i was planning to make my cursor redirect as the mouse move on stage

it did work but not as i expected it is something related to center

var rotationIs:Number = this.cursor.rotation;
this.cursor.x = stage.stageWidth/2;
this.cursor.y = stage.stageHeight/2;
//
stage.addEventListener(MouseEvent.MOUSE_MOVE, CReplace);
Mouse.hide();
//
function CReplace(event:MouseEvent):void
{
this.cursor.x= mouseX;
this.cursor.y= mouseY;
this.cursor.visible = true;
if (Mouse.hide()== false){
Mouse.hide();
}
//
this.cursor.rotation = ((Math.atan2(mouseY,mouseX))*180/Math.PI);
trace("rotationIs = "+((Math.atan2(mouseY,mouseX))*180/Math.PI));
};



but what i was thinking to do is to have something like

mouseXnow = mouseX;

but i do not know how to make the previus mouseX position?

i was planning to make the direction as if
directionX = mouseXnow - mouseXprev;


actually i did get lost ... any ideas or how to deal with such thing?

deadlock32
08-05-2007, 12:42 AM
have you tried calculating the rotation before you update the cursor.x and cursor.y?


var rotationIs:Number = this.cursor.rotation;
this.cursor.x = stage.stageWidth/2;
this.cursor.y = stage.stageHeight/2;
//
stage.addEventListener(MouseEvent.MOUSE_MOVE, CReplace);
Mouse.hide();
//
function CReplace(event:MouseEvent):void
{
this.cursor.rotation = ((Math.atan2(mouseY,mouseX))*180/Math.PI);
trace("rotationIs = "+((Math.atan2(mouseY,mouseX))*180/Math.PI));

this.cursor.x= mouseX;
this.cursor.y= mouseY;
this.cursor.visible = true;
if (Mouse.hide()== false){
Mouse.hide();
}

};

joshstrike
08-05-2007, 01:17 AM
you need to find a way to cache the last position(s) and derive a likely vector that the mouse is traveling upon. I'd suggest pushing the current mouseX and mouseY as an object onto an array with each turn, where when that array has more than 3-5 items you start shifting items off the front. Then use position 0 in the array as the center of a circle for which the last position defines the radius and derive the angle from that...