我发布了一个关于在像素图上绘制文本以在运行时生成动态纹理的问题,这个问题在这里得到了解决
有没有一种简单的方法可以为复制到新像素图的字体着色,还是需要逐个像素地手动进行着色?我在 libgdx 库或 Google 上找不到任何明显的东西。
我目前的流程是:
- 创建一个新的像素图
- 在该像素图上绘制一个字符
- 将像素图转换为纹理以进行渲染。
在该过程中的某个时刻,我希望能够在运行时为字体着色。
更新代码以测试 Jyro117 的答案。(不工作,见下图)
// Set up the base image
Pixmap newPixmap = new Pixmap(backImage.getWidth(),
backImage.getHeight(), Format.RGBA8888);
newPixmap.drawPixmap(backImage, 0, 0);
// Copy out the letter from our fontsheet
// and draw the char to a new pixmap
Glyph glyph = fontData.getGlyph(getLetterToDraw().charAt(0));
Pixmap charPixmap = new Pixmap(glyph.width, glyph.height,
Format.RGBA8888);
charPixmap.drawPixmap(fontPixmap, 0, 0, glyph.srcX, glyph.srcY,
glyph.width, glyph.height);
// try to tint it?!
charPixmap.setColor(1, 0, 0, 100);
charPixmap.fillRectangle(0, 0, newPixmap.getWidth(),
newPixmap.getHeight());
// copy the character to our new bitmap
newPixmap.drawPixmap(charPixmap, (BLOCK_SIZE - glyph.width) / 2,
(BLOCK_SIZE - glyph.height) / 2);
texture = new Texture(newPixmap);
newPixmap.dispose();
charPixmap.dispose();