dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: rotating around a mouse click

Hybrid View

  1. #1
    Registered User
    Join Date
    Mar 2001
    Posts
    46

    rotating around a mouse click

    hi i am trying to work out how to get a mc (with a button inside) to rotate using the coords of where the user has clicked on it and not the registration point of the clip.

    any ideas? thx in advance

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    This code assumes the movieclip is pointing to the right (3:00) when the rotation is 0.

    code:

    on(press)
    {
    var dy = _xmouse;
    var dy = _ymouse;
    var ang = Math.atan2(dy, dx);
    _rotation = ang * 180/Math.PI;
    }



    If the center of rotation is something other than 0,0, then you need to subtract it from _xmouse and _ymouse when computing dy and dx.

  3. #3
    Registered User
    Join Date
    Mar 2001
    Posts
    46
    hi

    cheers jbum for your quick answer. i didnt explain it at all well in the first post. sorry

    i am trying to get the object to kind of "hang" from the point that it is clicked on. so if its clicked on the right edge the left edge drops below (rotates around the mouse click) and visa versa.

    if you have any further idea on this i would really appreciate it.

    cheers

  4. #4
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Ah, this is doable. Can I assume the center of gravity is in the center of the object, and (hopefully) is aligned on the crosshairs? If so, basically you want to tween the rotation to -90 if _xmouse is > 0 and to 90 if _xmouse is < 0.

    Getting it to dangle realistically (and do a pendulum swing, tilt if tragged quickly etc) would be a bit more of a challenge, however.

  5. #5
    Registered User
    Join Date
    Mar 2001
    Posts
    46
    hi jbum. sorry if i am being thick

    -90 if _xmouse is > 0 and to 90 if _xmouse is < 0
    how do i fit that last bit into the previous piece of code?

    Getting it to dangle realistically (and do a pendulum swing, tilt if dragged quickly etc) would be a bit more of a challenge, however.
    yeh thats what i was eventuallly hoping for.. eventually.

    is that going to be amazingly difficult? typically my imagination is ahead of my skill level! if so maybe i should try to simplfy my idea

    cheers for very much for taking the time to help a partially understanding actionscript wannabe

  6. #6
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Yeah, it's going to be difficult. Did I say easy? heh.

    The other thing that is going to be difficult is the origin of rotation. Rotations usually happen around a fixed point, but in this case you want it to rotate around the spot the mouse pressed.

    One way to accomplish this is to use two (nested) movieclips, and reposition them when the mouse-down happens. The inner clip gets positioned so that it's _x and _y are such that 0,0 corresponds to where you pressed. The outer clip gets repositioned so that no apparent change happened. Then you can rotate the outer clip and the inner clip will rotate about 0,0 (the point you pressed).
    Last edited by jbum; 08-18-2004 at 11:42 PM.

  7. #7
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    I've attached a project file to help you get started, called pendulum_drag. Try dragging the red bar. This one doesn't compensate when you drag to the left and right, but it's a start.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    Mar 2001
    Posts
    46
    cheers mate, thanks a lot for al your help. and you never know, maybe, one day i may be able to help you out

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