# LibGDX How can I draw a line at a specific angle

I'm working on a 2D platformer, shooter game and I'm attempting to draw a line to serve as a guide to indicate where the player is shooting. The line should be drawn from the player's sprite to the mouse's position. I need to draw a line between the player and the mouse, at the angle from the player to the mouse, how can I do something like this? Here is a concept picture to explain what I'm talking about:

• Which aspect do you have a problem with? Do yoh want the line to always have the same length? – Bálint Feb 1 '17 at 6:47

you should use ShapeRenderer for this.

batch.begin();
// Draw sprites and stuff here so the line will be draw on them and not under
batch.end();

shapeRenderer.begin(ShapeType.Line);
shapeRenderer.setColor(1, 0, 0, 1); // Red line
shapeRenderer.line(player.x, player.y, mouse.x, mouse.y);
shapeRenderer.end();


This will let you draw a red line between the player and the mouse, the angle will be determined automatically by the x,x2 and y,y2. (You can still compute it if you want to).

I let you the implementation part (draw only on some conditions etc)