实际上可能是您正在缩放字体。
我遇到了这个问题,理解(并且修复)非常复杂。
基本上,当您缩放字体时,BitmapFont 通过除/乘来更改 BitmapFontData 中的值。如果您使用大量不同的值(或值的不幸组合)进行大量缩放,则可能会引入舍入错误,从而导致字体边缘闪烁。
我最终实现的解决方案是编写一个 Fontholder 来存储所有原始 BitmapFontData 值。然后我将字体数据重置为每一帧开始时的那些原始值(即 render() 方法的开始)。
这是代码...
package com.bigcustard.blurp.core;
import com.badlogic.gdx.graphics.g2d.*;
public class FontHolder {
private BitmapFont font;
private final float lineHeight;
private final float spaceWidth;
private final float xHeight;
private final float capHeight;
private final float ascent;
private final float descent;
private final float down;
private final float scaleX;
private final float scaleY;
public FontHolder(BitmapFont font) {
this.font = font;
BitmapFont.BitmapFontData data = font.getData();
this.lineHeight = data.lineHeight;
this.spaceWidth = data.spaceWidth;
this.xHeight = data.xHeight;
this.capHeight = data.capHeight;
this.ascent = data.ascent;
this.descent = data.descent;
this.down = data.down;
this.scaleX = data.scaleX;
this.scaleY = data.scaleY;
}
// Call this at start of each frame.
public void reset() {
BitmapFont.BitmapFontData data = font.getData();
data.lineHeight = this.lineHeight;
data.spaceWidth = this.spaceWidth;
data.xHeight = this.xHeight;
data.capHeight = this.capHeight;
data.ascent = this.ascent;
data.descent = this.descent;
data.down = this.down;
data.scaleX = this.scaleX;
data.scaleY = this.scaleY;
}
public BitmapFont getFont() {
return font;
}
}
我对此并不疯狂,因为它有点hacky,但它是必要的邪恶,并且会完全正确地解决问题。