Reputation: 352
Consider I have to create a custom/complex shape composed by some elements, inluding lines, rects and/or curves (bezier, cubic...). In standard Java we have the Path2D element, which allows us to perform some of those elements by going through predefined points. The following method demonstrates a simple approach to return a path
by some points:
private Path2D aShape(double x, double y) {
ArrayList<double[]> points = new ArrayList<>(
Arrays.asList(
new double[]{x, y},
new double[]{x - (L * 0.2588190451), y - (L * 0.4482877361)},
new double[]{x, y - (L * 0.7071067812)},
new double[]{x + (L * 0.2588190451), y - (L * 0.4482877361)}));
Path2D path = new Path2D.Double();
path.moveTo(points.get(0)[0], points.get(0)[1]);
for (int i = 1; i < points.size(); ++i) {
//line or anything avaliable...
path.lineTo(points.get(i)[0], points.get(i)[1]);
}
path.closePath();
return path;
}
After, this method can be drawn by a Graphics2D
. However, I din't found (yet, at least) any element that works in this way or even a element that supplies functions to draw curves or something like that, as Path2D, in LibGDX library.
For my tests I'm trying to draw a music treble_clef by following path, but didn't found a trick to do that.
What could be a approach to perform custom shape drawing in LibGDX by a passed path?
Upvotes: 0
Views: 231
Reputation: 91
You should use ShapeRenderer. It has methods for drawing lines, arcs, rects an so on.
Upvotes: 2