Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Positioning - moving objects

    I have some moving objects & they are using the top left spot of the object to 'hold' or 'pivot' off.

    Could someone tell me how i make the 'pivot' point in the centre of the image.

    I think it is somewhere in this section of code:
    Code:
    var k = 0
    function earth(){                     //controls earth and its satellite
    var kr = (k *Math.PI)/360
    var xearth = a - 1.5*r*Math.cos(kr)- 12
    var yearth = b - 1.47*r*Math.sin(kr)
    var xmoon = xearth - 2.4*rm*Math.cos(25*k)
    var ymoon = yearth + 2.0*rm*Math.sin(25*k)
    document.getElementById('earth').style.left = xearth
    document.getElementById('earth').style.top = yearth
    document.getElementById('moon').style.left = xmoon
    document.getElementById('moon').style.top = ymoon
    k++
    if (k >7200){k=0}
    }
    setInterval('earth()', 182.6)
    Thanks

    Blanky

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,861
    Thanks
    78
    Thanked 4,418 Times in 4,383 Posts
    Just offset by half the width/height of the image.

    That is, if you want the center of the image to be at location ( x , y ) you must set the top left point to be at ( x - widthOfImage/2, y - heightOfImage/2 ).

    That's all.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •