1

I am making a little game in Windows Forms where my main character has to catch butterflies within a certain time limit. The character moves with a KeyDown event of the arrow keys, there is a progress bar that shows elapsed time (it fills with the Tick event of a timer) and butterflies move around the screen randomly with the help of another timer. The form is repainted in the Tick event of the ButterflyMovement timer and in the KeyDown event.

My main problem is that whenever I hold down any of the arrow keys, the progressbar stops filling and the butterflies stop moving. When I let go of the key, the pbar resumes its filling and the butterflies start moving again. I am guessing the problem has to do with the KeyDown event causing some kind of loop that stops the timers when the key is held down . How can I solve this so the timers keep ticking while a key is being held? and, is this even the problem? I suppose there must be a way, but I have a hunch that it might have something to do with the limitations of doing a game in WinForms.

0

1 Answer 1

0

On key press, start a timer that moves the character to a certain direction, depending on the key. On key up, stop that timer.

Will the character look like Spongebob? I wanna play.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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