I’m creating a simple button class, with Slick2D library.
However, I have a problem, on how to create a buttonReleased function.
So problem is, I click the button, and it already executes, with out releasing a mouse click.
What I want to achieve, is, I click the button, but execute only if a mouse click is released inside a button area.
public boolean isActionPerformed(Input input, int mx, int my) throws SlickException {
if (buttonContains(mx, my)) {
if (buttonPressed(input)) {
return true;
}
if (buttonDown(input)) {
}
}
return false;
}
public boolean buttonContains(int mx, int my) throws SlickException {
if ((mx > minX && mx < maxX) && (my > minY && my < maxY)) {
buttonState = ButtonState.Over;
return true;
}
buttonState = ButtonState.Normal;
return false;
}
public boolean buttonPressed(Input input) throws SlickException {
if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)) {
return true;
}
return false;
}
public boolean buttonDown(Input input) throws SlickException {
if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
buttonState = ButtonState.Down;
return true;
}
return false;
}