Java Slick2D不会渲染所有鼠标平均区域

Java Slick2D不会渲染所有鼠标平均区域,java,slick2d,Java,Slick2d,我正在用Slick2D用Java编写一个小游戏。 对于我的主菜单,我有4个按钮,我使用MouseOverAreas来表示这些按钮。 问题是,我创建的最后一个鼠标平均区域没有呈现。 我把它们画成这样 @Override public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException { this.renderButtons(container, g);


我正在用Slick2D用Java编写一个小游戏。

对于我的主菜单,我有4个按钮,我使用
MouseOverAreas
来表示这些按钮。
问题是,我创建的最后一个
鼠标平均区域没有呈现。

我把它们画成这样

@Override
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
    this.renderButtons(container, g);
}

private void renderButtons(GameContainer container, Graphics g) {
    this.buttonStartGame.render(container, g);
    this.buttonSettings.render(container, g);
    this.buttonAchievements.render(container, g);
    this.buttonClose.render(container, g);
}
@Override
public void init(GameContainer container, StateBasedGame game) throws SlickException {
    this.initButtons(container);
}

private void initButtons(GameContainer container) throws SlickException {
    this.buttonStartGame = createButton(container, "Start Game", 0);
    this.buttonSettings = createButton(container, "Settings", 1);
    this.buttonAchievements = createButton(container, "Achievements", 2);
    this.buttonClose = createButton(container, "Exit", 3);

//      MouseOverArea foobar = createButton(container, "Foobar", 5);
}

private MouseOverArea createButton(GameContainer container, String text, int buttonIndex) throws SlickException {
    /* x, y, width and height are calculated so that I can use them.
       They all are local variables with the right values but the code for them is not important */

    Image image = new Image(width, height);
    Graphics g = image.getGraphics();

    int textX = (width - g.getFont().getWidth(text)) / 2;
    int textY = (height - g.getFont().getHeight(text)) / 2;

    g.drawString(text, textX, textY);

    MouseOverArea button = new MouseOverArea(container, image, x, y, width, height, this::onComponentActivated);
    button.setNormalColor(Color.white);
    button.setMouseOverColor(Color.gray);
    button.setMouseDownColor(Color.darkGray);

    return button;
}
但是
按钮关闭
不会被渲染。。。我创建了这样的按钮

@Override
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
    this.renderButtons(container, g);
}

private void renderButtons(GameContainer container, Graphics g) {
    this.buttonStartGame.render(container, g);
    this.buttonSettings.render(container, g);
    this.buttonAchievements.render(container, g);
    this.buttonClose.render(container, g);
}
@Override
public void init(GameContainer container, StateBasedGame game) throws SlickException {
    this.initButtons(container);
}

private void initButtons(GameContainer container) throws SlickException {
    this.buttonStartGame = createButton(container, "Start Game", 0);
    this.buttonSettings = createButton(container, "Settings", 1);
    this.buttonAchievements = createButton(container, "Achievements", 2);
    this.buttonClose = createButton(container, "Exit", 3);

//      MouseOverArea foobar = createButton(container, "Foobar", 5);
}

private MouseOverArea createButton(GameContainer container, String text, int buttonIndex) throws SlickException {
    /* x, y, width and height are calculated so that I can use them.
       They all are local variables with the right values but the code for them is not important */

    Image image = new Image(width, height);
    Graphics g = image.getGraphics();

    int textX = (width - g.getFont().getWidth(text)) / 2;
    int textY = (height - g.getFont().getHeight(text)) / 2;

    g.drawString(text, textX, textY);

    MouseOverArea button = new MouseOverArea(container, image, x, y, width, height, this::onComponentActivated);
    button.setNormalColor(Color.white);
    button.setMouseOverColor(Color.gray);
    button.setMouseDownColor(Color.darkGray);

    return button;
}
但是,如果我也创建了这个
foobar
,关闭按钮将被呈现。

我是否遗漏了什么,或者为什么我创建的最后一个鼠标区域永远无法呈现?

我不确定原因,但调用
g.destroy()
完成了任务