【发布时间】:2016-06-21 21:16:42
【问题描述】:
所以我有一个我创建的按钮的 ArrayList,除了这一点之外,它们大部分都可以正常工作。我将通过这些步骤找到给我带来问题的部分。
ArrayList 创建和更新
private ArrayList<PressButton> buttons;
public CharacterSelectionMenu()
{
buttons = new ArrayList<PressButton>();
addButtons();
}
public void update()
{
updateButtons();
}
private void updateButtons()
{
for(PressButton b : buttons)
{
b.update();
}
}
private void addButtons()
{
buttons.add(new CreateCharacterButton(100, 100, 64, 64));
buttons.add(new CreateCharacterButton(200, 100, 64, 64));
buttons.add(new CreateCharacterButton(300, 100, 64, 64));
buttons.add(new CreateCharacterButton(100, 200, 64, 64));
buttons.add(new CreateCharacterButton(200, 200, 64, 64));
buttons.add(new CreateCharacterButton(300, 200, 64, 64));
}
PressButton 超类中的方法,当鼠标悬停在按钮上时绘制正方形
public void update()
{
input();
draw();
hover();
}
protected void hover()
{
if(Collision.mouseAABBButton(this))
{
drawQuadColor(1, 1, 1, 0.3f, x, y, width, height);
}
}
drawQuadColor 方法(以防万一,这在我使用它的任何地方都有效,我认为这不是问题的原因)
public static void drawQuadColor(float r, float g, float b, float a, float x, float y,
float width, float height)
{
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(r, g, b, a);
glBegin(GL_QUADS);
glVertex2f(x, y);
glVertex2f(x + width, y);
glVertex2f(x + width, y + height);
glVertex2f(x, y + height);
glEnd();
glDisable(GL_BLEND);
}
所以这是一个奇怪的问题,我猜它很简单,并且与 ArrayList 中的更新顺序有关,但我太笨了,无法弄清楚。
如果我将鼠标悬停在 ArrayList 中的最后一个按钮上,它就可以正常工作,如下所示:
但是,如果我将鼠标悬停在任何其他按钮上,则悬停在其上的按钮应该会正常工作,但是 ArrayList 中的下一个按钮会在它们上方出现一个不透明的正方形(“错误”的正方形不应该是至少透明?),像这样:
我也尝试过使用数组,但没有帮助。
我该如何解决这个问题?为什么会这样?
【问题讨论】: