I am currently using this method to draw dashed lines :
private void drawDottedLine(ShapeRenderer shapeRenderer, int dotDist, float x1, float y1, float x2, float y2) {
shapeRenderer.begin(ShapeType.Point);
Vector2 vec2 = new Vector2(x2, y2).sub(new Vector2(x1, y1));
float length = vec2.len();
for(int i = 0; i < length; i += dotDist) {
vec2.clamp(length - i, length - i);
shapeRenderer.point(x1 + vec2.x, y1 + vec2.y, 0);
}
shapeRenderer.end();
}
So basically I calculated the line vector to draw and loop it to draw points based on the desired distance to the point. In my test there was a pretty good distance:
drawDottedLine(shapeRenderer, 10, x1, y1, x2, y2);
This works pretty smoothly for me. If you have a better way to draw dashed lines, then please let me know.
source
share