I gotta tell you I didn't come up with a good title for the question, but I'll explain my situation.
I'm making a simple game in Java using OpenGL (JOGL). There is a key listener waiting for the left key to be pressed, and his happens when you press on the left key:
case KeyEvent.VK_LEFT:
if (inControl) {
inControl = false;
alpha = 0;
moving = true;
}
As you can see, inControl
decides if the player is able to make a move. Now by setting moving
to false, I'm "sending a signal" to the display
method, which contains the following code segment:
public void display(GLAutoDrawable drawable) {
.
.
.
if (moving) {
.
.
.
// Set color's alpha to alpha
// Draw contents
.
.
.
if (alpha < 1.0f)
alpha += 0.01f;
if (alpha >= 1.0f) {
inControl = true;
moving = false;
}
}
.
.
.
}
This means once I click left, somethings will gradually increase opacity until alpha >= 1.0f
. The player must wait then, and this is done by putting inControl = true
at the end of display method.
Although this works, I'm not a fan at all of this approach. Shouldn't the display method be exclusive to only displaying graphics, and not manipulate data?