Every time you draw something actually you are sending data from CPU to GPU. its the slow part of drawing somethings.
So if you have unique names for each monster only thing you can do is drawing texts via opengl but i dont know if its possible or not in libgdx.
If you are using same text for all monsters so its quite possible.
- Create pixmap
- Load font texture and data
- Write your string to pixmap
- Convert pixmap to texture
- Create sprite from texture
- Change position of sprite for each monster position.
- So when you drawing font you wont send data to GPU just going to change position of texture already exists on GPU.
Here is code for almost of them:
// load the background into a pixmap
Pixmap tile = new Pixmap(Gdx.files.getFileHandle("someFile.png", FileType.Internal));
// load the font
FileHandle handle=Gdx.files.getFileHandle("someFont.fnt",FileType.Internal);
BitmapFont font = new BitmapFont(handle);
// get the glypth info
BitmapFontData data = font.getData();
Pixmap fontPixmap = new Pixmap(Gdx.files.internal(data.imagePaths[0]));
Glyph glyph = data.getGlyph(getLetterToDraw().charAt(0));
// draw the character onto our base pixmap
//You can use method for draw string to pixmap char by char.
tile.drawPixmap(fontPixmap, (TILE_WIDTH - glyph.width) / 2, (TILE_HEIGHT - glyph.height) / 2,glyph.srcX, glyph.srcY, glyph.width, glyph.height);
// save this as a new texture
sprite = new Sprite(new Texture(tile));