View Full Version : Positioning - moving objects

02-22-2009, 04:30 PM
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:

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
if (k >7200){k=0}
setInterval('earth()', 182.6)



Old Pedant
02-22-2009, 10:29 PM
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.