Page 1 of 1
Rotating around an object [Solved]
Posted: Thu May 01, 2014 9:50 pm
by lilfinn
im wondering how to point an arrow toward the mouse by rotating around another object like this:
where the arrow is pointing in the direction of the mouse. Is there a way to change the point an object rotates around?
Thanks in advance
Re: Rotating around an object
Posted: Thu May 01, 2014 9:54 pm
by bartbes
It depends what the object is. If it's an image, you can use the ox and oy parameters to set the point around which it rotates.
Re: Rotating around an object
Posted: Thu May 01, 2014 10:06 pm
by lilfinn
thanks for the quick reply.The object is an image and i tried using the ox and oy parameters but all that does is offset the origin, the arrow still just rotates around itself instead of the around the circle. any idea on how i can achieve what im looking for?
Re: Rotating around an object
Posted: Thu May 01, 2014 11:55 pm
by micha
You can do it using ox and oy. First draw the circle as usual. Then draw the arrow like this:
Code: Select all
love.graphics.draw(arrowImage, x,y,angle, 1,1,ox,oy)
For x and y, insert the center of the circle (that would be the drawing coordinates plus half of the diameter) for angle insert whatever angle and for ox and oy insert a point that is outside the arrow-image. If for example, the arrow image has a size of 16x16 pixels and the arrow is pointing upwards, select as a drawing origin (8,50). This is the point inside the image, that will be aligned with the center of the circle.
Re: Rotating around an object
Posted: Fri May 02, 2014 4:07 am
by lilfinn
Thank you very much, after you explained the offset it made perfect sense.
Thank you again