Fofole
Fofole

Reputation: 3548

Android AndEngine change text dynamically

I am using custom font in andengine and when the user click that ui I need to change the color of my ui.Here is my code.

Text exit=new Text(250, 390, this.mPlokFont, "Exit");
exit.setColor(255,0, 0, 255);  
scene.attachChild(exit); 

but it doesn't work. My font :

mPlokFont = FontFactory.createFromAsset(this.mPlokFontTexture, this, "Plok.ttf", 16, true, Color.WHITE);

Thanks in advance.

Upvotes: 1

Views: 4352

Answers (2)

LintfordPickle
LintfordPickle

Reputation: 410

I'm pretty sure you are facing this issue because you are using premultiplied alpha in the font texture. Try this

mFontTexture = new BitmapTextureAtlas(256, 256, TextureOptions.BILINEAR);
mUIFont = new Font(m_FontTexture, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32, true, Color.WHITE);

and it should work. AFAIK, premultiplied alpha means the RGB values in the texture are already multiplied by an alpha value, so calling .setAlpha() will not change anything (it will not be applied.

Upvotes: 4

Greg
Greg

Reputation: 1152

Try to use ChangeableText instead of Text

Upvotes: 3

Related Questions