Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
1  
How much have you done so far? –  Mokosha Apr 18 '13 at 18:47

2 Answers 2

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

 
discard

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.