[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Show text on screen for a limited time



Are you using sprite Groups? In any case, a simple solution to me would be having the "Try Again" surface wrapped up in a sprite class along with a "lifetime" attribute you can set, then in the update() loop check to see if it's time to kill it or not, where killing could mean removing from a sprite group or setting a "visible" flag or however you're controlling which sprites get rendered when. "lifetime" can either be a number of frames, in which case you'd just decrement it on update(), or a number of seconds, which you can then compare with an initial "last_time" variable initialized with pygame.time.get_ticks(), and you just compare your lifetime var with (pygame.time.get_ticks() - self.last_time) to determine if it's time to kill it or not. If you re-add the sprite to a group later, you can reset/initialize the "last_time" var then.

Hope this helps,
-Kevin

On Mon, Jun 7, 2010 at 9:36 AM, Dan Ross <dan@xxxxxxxxxxxxxxxxxx> wrote:
Hi all-

I have a spelling game that has the user spell a word that matches the
picture shown.

When they press enter, the picture changes when correct and displays "Try
Again" if incorrect.

I can't seem to figure out a way to have "Try Again" display for only a
set time.

Any help would be appreciated.

Thanks,

Dan