A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Custom mouse pointer rotation is erratic

Threaded View

  1. #1
    Member
    Join Date
    Mar 2008
    Posts
    82

    Custom mouse pointer rotation is erratic

    Ok well I'm not really replacing the mouse cursor exactly. Just placing a custom image of a pointer below it so it will follow the mouse cursor as it moves around the screen. I want this pointer image to move with the mouse and to rotate and point in the direction the mouse is traveling. Simple stuff.

    The problem is that the rotation of the pointer graphic is not smooth at all. It is jumpy and somewhat erratic particularly at slower mouse speeds. When the mouse is moving quickly the problem seems to go away.

    What is going on here?

    PHP Code:
    package {
        
    import flash.display.Sprite;
        
    import flash.events.*;
        
        public class 
    MouseFollower extends Sprite {
            private var 
    pointer:Pointer = new Pointer(); // ...a simple triangle mc
            
            
    public function MouseFollower() {
                
    addChild(pointer);
                
    stage.addEventListener(MouseEvent.MOUSE_MOVEenterFrameHandler);
            }
            
            private function 
    enterFrameHandler(moved:MouseEvent):void {    
                var 
    dx:Number mouseX pointer.x;
                var 
    dy:Number mouseY pointer.y;
                var 
    angle:Number Math.atan2(dydx) * (180/Math.PI);

                
    pointer.rotation angle;
                
    pointer.mouseX;
                
    pointer.mouseY;
            }
        }

    Last edited by Trugas; 11-09-2009 at 07:31 PM. Reason: Simplifying code

    ----------------------------------------------------------------------1
    5-------------3-------------2-------------1-------------0-------------0
    -------0-------------0-------------0-------------0-------------0------0
    ----------------------------------------------------------------------0
    3-------------2-------------0-------------0---------------------------2
    --------------------------------------------------------3-------------3

Tags for this Thread

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