|
-
can i detect mouse direction?
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
Code:
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?
-
a.k.a gltovar
have you tried calculating the rotation before you update the cursor.x and cursor.y?
PHP Code:
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();
}
};
-
Senior Member
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...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|