Your laser is a single image?
Its actually two images. The first part is at the beginning, the part that grows. I did not include that in the post because I dont want to show unnecessary code.
I am also going to remove it.
I asked because maybe you where drawing the beam with lines and some effects instead of images, just wanted to be sure.
Does it spin from the center of one side or from the top-left corner?
Do you mean what point it rotates around? Since origin X and Y is 0, it should be the top-left corner.
Here is a youtube video I just made that should explain it better:
(Note that the black dot is srcX srcY point.
Thanks, that's what I thought.
If that's the case, I think that you're making the rotation right (there's nothing wrong with the code you posted), but you're drawing the laser wrong. You might want to translate the image so that the center of the origin side is at (originX,originY) position.
If I understand you correctly, I should set originY to the laser height / 2?
Not exactly, you need to make sure that the center of the origin side of the image is at the the originX and originY of the bean, so you need to draw it on another point. That point must be computed since it depends on the angle, if the beam points down the top-left corner of the beam image is translated height/2 in the X axis. You can use sin and cos functions to know how much to translate in each direction, dX = height/2*cos(angle + 90°) and dY = height/2*sin(angle + 90°), then you call:
srcX + dX,
srcY + dY,
MathStuff.distance(srcX, srcY, destX, destY),
Edit: Fixed an angle problem, you need to add 90° to the angle since you want dY = height/2 when your beam is horizontal. Also, if your Y axis starts from the top of the screen you should do dY = - height/2*sin(angle + 90°)
Edited by DiegoSLTS, 11 April 2014 - 11:18 AM.