【发布时间】:2014-07-19 18:45:01
【问题描述】:
我正在使用 java、libgdx、scence2d。
我在构造函数中设置了 bitMapFont。现在如何在创建后更改字体颜色?我想改变渲染方法。
这是我为标题和菜单项(3 个按钮)创建 BitmapFont 的构造函数
public menuScreen() {
sb = new SpriteBatch();
stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),
true);
bitMapFont = new BitmapFont(Gdx.files.internal("font/font.fnt"), false);
labelStyle = new LabelStyle(bitMapFont, Color.WHITE);
label = new Label("Asteroids", labelStyle);
float width = bitMapFont.getBounds(title).width;
label.setPosition((Gdx.graphics.getWidth() - width) / 2,
(Gdx.graphics.getHeight()) - 100);
stage.addActor(label);
//menu items
menuItems = new String[] { "Play", "HighScores", "Quit" };
label2 = new Label(menuItems[0], labelStyle);
label2.setPosition((Gdx.graphics.getWidth() - width) / 2,
(180 - 35 * 0));
label3 = new Label(menuItems[1], labelStyle);
label3.setPosition((Gdx.graphics.getWidth() - width) / 2,
(180 - 35 * 1));
label4 = new Label(menuItems[2], labelStyle);
label4.setPosition((Gdx.graphics.getWidth() - width) / 2,
(180 - 35 * 2));
stage.addActor(label2);
stage.addActor(label3);
stage.addActor(label4);
}
绘制标题和菜单项
public void draw() {
sb.setProjectionMatrix(MyGdxGame.camera.combined);
sb.begin();
//if user press 'Play' menu item
if(currentItem == 1){
//How to change label2 color??????
}
// update and draw stage
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
sb.end();
}
【问题讨论】:
-
能否请您提及这是哪种语言.. 也用该语言标记问题