A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: can i detect mouse direction?

  1. #1
    Junior Member
    Join Date
    Jun 2004
    Location
    Kwait
    Posts
    21

    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?

  2. #2
    a.k.a gltovar deadlock32's Avatar
    Join Date
    May 2001
    Location
    Naperville,IL
    Posts
    489
    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.stage.stageWidth/2;
    this.cursor.stage.stageHeight/2;
    //
    stage.addEventListener(MouseEvent.MOUSE_MOVECReplace);
    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.xmouseX;
        
    this.cursor.ymouseY;
        
    this.cursor.visible true;
        if (
    Mouse.hide()== false){
            
    Mouse.hide();
        }
        
    }; 

  3. #3
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center