resource.play() issue

17 views
Skip to first unread message

Jose

unread,
Jul 10, 2019, 8:57:45 AM7/10/19
to pyglet-users
Hi everyone

I am trying to create something similar to space invaders. In my game, the player launches bullets that bounce, and each time they bounce I want a sound to play.

I load all the sounds (wav format) using pyglet.media.load(path, streaming = False) before I call pyglet.app.run(), and when the game is running I play the sound using resource.play()

The thing is that when the first bullet bounces, the game freezes for a good 1-2 seconds (no sound also) and then the sound is played and the game continues. After that, the sounds just work perfect.

I have tried to find a solution, but I can't find anything that relates with what I am trying to solve (or at least I can't see how it's related). Hope you can find me, I am sure it's a mistake I am making or something that I don't fully understand.

Thanks
Jose

Benjamin Moran

unread,
Jul 13, 2019, 5:56:57 AM7/13/19
to pyglet-users
I've seen this before. Depending on the audio hardware, it might take it a second to "wake up" on first use. To work around it, you could play something as soon as your game starts. For example, a jingle on the title screen. Or maybe even silence using `media.synthesis.Silence(0.5)` if you don't want that.

-Ben

Reply all
Reply to author
Forward
0 new messages