【发布时间】:2014-02-22 02:22:25
【问题描述】:
我发布了一个关于在像素图上绘制文本以在运行时生成动态纹理的问题,该问题已解决here
有没有一种简单的方法可以为复制到新像素图的字体着色,还是需要逐个像素地手动进行着色?我在 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();
【问题讨论】:
-
可能会在Badlogicforum问整个流程的问题。在运行时从 Bitmapfont 到 pixermap... 像素图的 alpha 似乎有问题。它应该与叠加层一起使用,但 alpha 混合不正确。也许它不可能是你想要的。没有其他方法可以为像素图着色。否则,您需要在创建像素图之前为字体着色,但我认为不可能这样。
-
您可以使用 2 种字体:一种使用默认颜色,一种使用着色颜色并在它们之间切换。还是我误会了什么?
-
@Springrbua 是的,这是一个选项,面包然后我需要为我想要使用的每种颜色创建并存储一张表。
-
不能只给字体上色吗? BitMapFont.setColor(Color)?
-
我没有使用 BitmapFont 对象进行绘图,否则可以。