earlygrey / shapedrawer

A library for libGDX that draws simple shapes using a batch.
MIT License
185 stars 32 forks source link

Add more joins and caps #37

Open thelsing opened 3 years ago

thelsing commented 3 years ago

I'm porting a game from java 2d to libgdx. For lines I'm missing some parts of https://docs.oracle.com/javase/7/docs/api/java/awt/BasicStroke.html

As a workaround I draw lines a half a linewith longer on each side for CAP_SQUARE and draw filled circles on each side for CAP_ROUND.

For JOIN_ROUND I also draw circles on the points of the polygon.

I would be nice if I could set the the line end cap and the joins on the Shapedrawer object and have the line and path drawings use them automatically.

earlygrey commented 3 years ago

I think this would be a reasonably simple addition, you could just implement it as you have - draw filled circles for a CAP_ROUND enum and extend the line for a CAP_ROUND enum. There's already a JoinType enum, perhaps JOIN_ROUND could be added to that.

Since there are already so many overloaded drawing methods, the cap type might be best just set via drawer.setLineCapType() or something rather than adding it as an argument to line().

Frosty-J commented 1 year ago

Any new thoughts on this? It would be useful for me - I've been using the same workaround as OP, though it doesn't seem the most efficient approach in the world and prevents the use of transparency.