A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Arrow Rotation which follows Mouse?

  1. #1
    Big boy member
    Join Date
    Jun 2003
    Location
    Colorado
    Posts
    36

    Arrow Rotation which follows Mouse?

    Hello,

    I am trying to achieve an effect that I believe is probably fairly easy for the right person. Picture a flash movie with a crosshair pattern on it. In the middle of the cross hair I have a simple arrow which I simply want to rotate (staying centered), to point and follow the movement of the mouse on the screen. So basically all is said and done the arrow would be capble of rotating anywhere inbetween 360 degrees, depending on where the mouse is.

    Any help or direction would be most appreciated.
    If need be I can point you to a preview of the page I am trying to do this with.

    Thanks!


  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Does the arrow point *at* the mouse? Or does its position indicate the direction of mouse movement (e.g. if mouse moves up, arrow points up)?

  3. #3
    Big boy member
    Join Date
    Jun 2003
    Location
    Colorado
    Posts
    36
    The arrow would need to Point AT the mouse. So the tip of the arrow would always be pointing directly at the mouse.

  4. #4
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Does the crosshair movie move, or is it stationary? If it moves, what causes it to move?

  5. #5
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Attached is a movie which does what you describe.

    The code, attached to the crosshair movie, reads as follows:

    code:


    onClipEvent(enterFrame)
    {
    var dy = _root._ymouse - this._y;
    var dx = _root._xmouse - this._x;
    this.arrow._rotation = Math.atan2(dy,dx)*180/Math.PI;
    }

    Attached Files Attached Files

  6. #6
    Big boy member
    Join Date
    Jun 2003
    Location
    Colorado
    Posts
    36
    I took a peek at the clip you sent. Looks exaclty like what I need.
    Awesome, Thanks.

  7. #7
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Cool - remember that your arrow must point to the RIGHT when it is at zero rotation, in order for that code to work.

  8. #8
    Big boy member
    Join Date
    Jun 2003
    Location
    Colorado
    Posts
    36
    any way to get it so it can start off from 90 degrees, straight up?

  9. #9
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Yeah, change this line as follows:

    this.arrow._rotation = Math.atan2(dy,dx)*180/Math.PI + 90;

  10. #10
    Big boy member
    Join Date
    Jun 2003
    Location
    Colorado
    Posts
    36
    sweet.

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