我在 andengine 中使用自定义字体,当用户单击该 ui 时,我需要更改 ui 的颜色。这是我的代码。
Text exit=new Text(250, 390, this.mPlokFont, "Exit");
exit.setColor(255,0, 0, 255);
scene.attachChild(exit);
但它不起作用。我的字体:
mPlokFont = FontFactory.createFromAsset(this.mPlokFontTexture, this, "Plok.ttf", 16, true, Color.WHITE);
提前致谢。
最佳答案
我很确定您正面临这个问题,因为您在字体纹理中使用了预乘 alpha。试试这个
mFontTexture = new BitmapTextureAtlas(256, 256, TextureOptions.BILINEAR);
mUIFont = new Font(m_FontTexture, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32, true, Color.WHITE);
它应该可以工作。据我所知,预乘 alpha 意味着纹理中的 RGB 值已经乘以一个 alpha 值,因此调用 .setAlpha() 不会改变任何东西(它不会被应用。
关于Android AndEngine 动态改变文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8802490/