Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to display an image, then return to the previous after one second when a certain key is pressed. I'm using Slick2d and Java. How can I accomplish this?

share|improve this question
How much have you done so far? – Mokosha Apr 18 '13 at 18:47
up vote 2 down vote accepted

When you display the image you just need to keep track of some "elapsed time" variable and update it by the delta time each frame. When that elapsed time variable hits whatever time limit you want, then you switch the image back.

share|improve this answer

Use a timer for this, and make sure to connect its timeOut -- or similar -- method to the method responsible for switching between images.

Inside the key press event handler you check whether the timer is already running, if not, start it and it's done.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.