【发布时间】:2014-03-06 13:15:22
【问题描述】:
我想更改文本的颜色和大小。我只想为此使用一种字体。有可能吗?
这是我的代码:定义字体和文本
// for red color font
redFont = FontFactory.createFromAsset(activity.getFontManager(),
fontTexture, activity.getAssets(), "YIKES__.TTF", 30, true,
Color.parseColor("#EF522A"));
redFont.prepareLetters("Score:1234567890 Sec Cash / Level"
.toCharArray());
redFont.load();
// for white color font
ITexture whiteFontTexture = new BitmapTextureAtlas(
activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR);
whiteFont = FontFactory.createFromAsset(activity.getFontManager(),
whiteFontTexture, activity.getAssets(), "YIKES__.TTF", 30, true,
Color.WHITE);
whiteFont.prepareLetters("Score:1234567890 Sec Cash / Level"
.toCharArray());
whiteFont.load();
然后初始化文本并更改大小,如:
gameOverText = new Text(0, 0,
ResourcesManager.getInstance().whiteFont,
"ABCDEFHIJKLMNOPQRSTUVWXYZ",
ResourcesManager.getInstance().vbom);
gameOverText.setPosition(45, 72);
// gameOverText.setSize(490, 115);
gameOverText.setText(gameOver);
然后改变颜色:
// define the color
pColor = new org.andengine.util.color.Color(255, 102, 51);
gameOverText.setColor(pColor);
但我没有取得成功。如此接近低于一个。
【问题讨论】:
-
我以前遇到过这种方式的问题,但不记得解决方案了。它与 alpha 通道有关 - 查看我的代码,要获得除白色以外的颜色,我还必须使用此 Color.argb(int alpha, int red, int green, int blue) 设置 alpha 通道 - 尝试那而不是你的 parseColor 调用
标签: android text fonts andengine