I am working on a 2D grand strategy game (like Hearts of Iron from Paradox but as I said only 2D game) and I would like to render the area names on the map. I made the Polygons for each area. How can I render a String inside that polygon?
Here is the image from my game (I put some area names onto the image to show what I would like to achieve):
Here is the code where the polygon is being made (please check it because this is the first time I use polygons):
private Polygon pol;
public Polygon polygon(Map m) {
if (pol == null) {
float[] vertices = new float[border().size * 2]; // the border() method returns a collection of 2D vectors/points which are the borders.
for (int i = 0; i < vertices.length; i += 2) {
Vector2 v = border().get(i / 2);
vertices[i] = v.x;
vertices[i + 1] = m.height - v.y - 1; // m.height is the map's height which is 2160; I convert here the coords (not sure if it is neceseray, the top left corner is the 0,0 coord in the map)
}
pol = new Polygon(vertices);
pol.setPosition(0, 0);
pol.setOrigin(0, 0);
}
return pol;
}
How I checked if the area is on the screen:
private Vector3 ivm = new Vector3();
public boolean isVisible(Camera cam) {
for (Vector2 vec : points) {
ivm.set(vec, 0);
if (cam.frustum.pointInFrustum(ivm)) {
return true;
}
}
return false;
}