||01-12-2012 03:48 AM
User input problem
It is my first game and I need to know how to, for lack of a better word, pause the program but still run my animations and only stop them and continue the program when it receives use input.
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_g:
if event.key == K_r:
if event.key == K_q:
if event.key == K_i:
When I run it and press "g" it does as shown BUT I don't know how to make it wait until either "r" or "q" is pressed. Thank you and yes I am a noob.
||01-12-2012 06:32 AM
You would have to run your animation code inside a sentinel type loop such as a while loop. The sentinel condition being that you received the correct user input which would cause the loop to exit and continue on. This probably won't work exactly as you are expecting because Python is after all a scripting language and executes the commands in the script line by line. You might be able to achieve something more like you would want if you involved threading in which case you could perform multiple tasks simultaneously but threading can be difficult to get right.
userInput = ""
while userInput != "r" or userInput !="q":
userInput = lower(raw_input("Enter letter: "))
This setup would run the animation once per iteration of the loop and at the end of the loop ask the user for input. Until they enter r or q it will continue to loop.
|All times are GMT +1. The time now is 12:41 AM.
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.