DaniPaniz
DaniPaniz

Reputation: 1068

how can I play a sound with pygame while the system is waiting?

I'm using the pygame function pygame.time.delay() to make pygame freeze while presenting some pictures or text, and I want to play a sound at the same time.

The problem, I think, is that in order for pygame mixer to work the main loop must be running, so putting the system on wait it also stops the mixer.

Any easy way to solve this problem? thanks

Upvotes: 0

Views: 267

Answers (1)

pmoleri
pmoleri

Reputation: 4449

pygame.time.delay() is a bad idea for waiting while presenting things, it not only will prevent you from playing music it can also freeze your screen (blank screen).

You should process events and update the display although you have static image.

Some alternatives are:

  1. Use a counter in your loop to know how long you should keep the same image in the screen.
  2. Use a timer to receive a User Event that will notify you that you need to change the current state.

Upvotes: 2

Related Questions