I have a question for you:
in my tiled map I added a rectangle object.
My question is:
How Do I add a text label in this rectangle by code?
In particular:
when I render tiled map for every rectangle object in the map I want to add in this rectangle a text label
Now I tried this:
for(MapObject obj: tiledMap.getLayers().get("object").getObjects()){
if(obj instanceof RectangleMapObject){
//I don't know what do
}
Add text as a property to your rectangle in tmx editor (just click on rectangle twice if you use Tiled), like this:
has_text (key) - any text (value)
Than check if RectangleMapObject
has the "has_text" key property, like this:
MapProperties properties = object.getProperties();
if (properties.containsKey("has_text")) {
String textToSet= (String) properties.get("has_text");
float x = (Float) properties.get("x");
float y = (Float) properties.get("y");
//Now create you can create the label, you have text(seted in tmx editor)
//and x,y are coordinates of the rectangle.
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.