1
我正在使用Slick2D,LWJGL的包裝。我正嘗試對字符串的字體大小進行動畫/縮放,而不需要爲每個渲染創建新的Font和TrueTypeFont的性能成本。這是我目前有:如何在Slick2D中動畫字體大小,而不創建每個呈現的新字體實例?
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
Font pulsingFont = new Font("Verdana", Font.PLAIN, (int) Math.abs(Math.sin(frameCount) * 20) + 10);
TrueTypeFont pulsing = new TrueTypeFont(pulsingFont, true);
pulsing.drawString(200, 200, "Pulsing Text", Color.black);
}
public void update(GameContainer gc, StateBasedGame sbg, int DELTA) throws SlickException {
frameCount += 0.1;
}
我知道要改變字體大小的唯一方法是在字體,這意味着我還需要做出TrueTypeFont 每一幀的新實例。僅僅這些線條就會造成巨大的滯後。
那麼有沒有辦法讓動畫的字體大小,而不是每幀創建一個新的實例?