在朋友的帮助下,我想出了如何做到这一点。我确信这是非常基本的,但这是我想要的方式,不使用 XML 文件,也没有可以随时更改的文本。
// Text related fields.
private ChangeableText mText;
private Font mFont;
在 OnLoadResources
public void onLoadResources() {
this.mFontTexture = new BitmapTextureAtlas(256, 256, TextureOptions.BILINEAR);
this.mFont = new Font(this.mFontTexture, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32, true, Color.BLACK);
//Don't forget to load the font (along with other images)
this.mEngine.getTextureManager().loadTextures(this.mTimerImage, this.mbackgroundImage, this.mFontTexture);
this.mEngine.getFontManager().loadFont(this.mFont);
在 OnLoadScene 中
public Scene onLoadScene()
{
final Scene scene = new Scene();
//Initialise your other variables...
//Give your text a position on screen, font, and fill it with some text and character count
//I used it for a score to be shown.
mText = new ChangeableText(490, 800, GameActivity.this.mFont, "", 20);
scene.attachChild(mText);
return scene;
}
我将我的文本用于稍后在游戏中显示的可变分数,并且每次玩家的分数增加时,我都会调用 Score 方法。
private void Score(int value)
{
playerScore += value;
mText.setText(String.valueOf(playerScore));
}
这更新了每一帧的分数,因为我从我的更新方法中调用它。