Java LibGDX BitmapFont setScale 方法无效

Java LibGDX BitmapFont setScale method not working

我目前正在尝试缩放字体,但收到错误消息 "the method setScale(float, float) is undefined for the type BitmapFont" 这是我收到错误的代码部分,特别是在第 2 行和第 4 行。

    font = new BitmapFont(Gdx.files.internal("text.fnt"));
    font.setScale (.25f, -.25f);
    shadow = new BitmapFont(Gdx.files.internal("shadow.fnt"));
    shadow.setScale (.25f -.25f);

我在这里创建了变量

  public static  BitmapFont font;
public  static BitmapFont shadow;

当我查看其他使用 setScale 函数的示例时,这似乎是使用的格式。关于为什么会发生这种情况的任何想法?

此方法在 BitmapFont class.

中不再存在

一个API change for the Bitmap* classes has been introduced with LibGDX 1.5.6 (released in April 2015) as explained in this libgdx team blog post。 您遵循的教程现在可能已经过时了。

长话短说,使用最新的 libgdx 版本,您应该可以做到:

font.getData().setScale(.25f,.25f);