我有这个课程,我注意到如果我使用setFont(...)
它会减慢整个程序的执行速度。
public class MenuState extends GameState {
private String[] options = { "Start ", "Options","Quit"};
private int currentSelection;
private Font font;
protected MenuState(GameStateManager gameStateManager) {
super(gameStateManager);
init();
}
public void init() {
currentSelection = 0;
font = new Font("Times New Roman", Font.BOLD, 30);
}
public void update() {
}
public void render(Graphics graphic) {
for (int i = 0; i < options.length; i++) {
if (i == currentSelection) {
graphic.setColor(Color.GREEN);
} else {
graphic.setColor(Color.BLACK);
}
if (i == 0) {
graphic.setFont(font);
graphic.drawString(options[i],
GuiDimension.WIDTH.getValue() / 2 - 47, 500);
}
if (i == 1) {
graphic.setFont(font);
graphic.drawString(options[i],
GuiDimension.WIDTH.getValue() / 2 - 107, 550);
}
if (i == 2) {
graphic.setFont(font);
graphic.drawString(options[i],
GuiDimension.WIDTH.getValue() / 2 - 47, 600);
}
}
}
现在,如果我评论这一行:
graphic.setFont(font);
执行正常,否则很慢。
有人可以告诉我原因吗?