Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 创建字体后如何更改字体颜色_Java_Fonts_Libgdx_Scene2d - Fatal编程技术网

Java 创建字体后如何更改字体颜色

Java 创建字体后如何更改字体颜色,java,fonts,libgdx,scene2d,Java,Fonts,Libgdx,Scene2d,我正在使用java、libgdx、scene2d 我已经在构造函数中设置了位图字体。现在,如何在创建字体后更改字体颜色?我想更改渲染方法 这是我的构造函数,我在其中为title和menuItems3按钮创建位图字体 public menuScreen() { sb = new SpriteBatch(); stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);

我正在使用java、libgdx、scene2d

我已经在构造函数中设置了位图字体。现在,如何在创建字体后更改字体颜色?我想更改渲染方法

这是我的构造函数,我在其中为title和menuItems3按钮创建位图字体

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();
}

如果您从未计划更改任何一个标签的颜色,那么只需为其指定一个不同的标签样式即可,在标签样式中指定所需的颜色


如果您想随意更改标签的颜色,请在设置标签的新文本之前使用label.getBitmapFontCache.setColor。

请说明这是哪种语言。。也用这种语言标记问题