[PyGame] Help on a time issue

[PyGame] Help on a time issue

Postby Donald8274 » Thu Jun 06, 2013 8:10 am

Hello, I'm creating a game you will all know, Pong, I actually have everything running good (movements, collision detection, ect). I need help on a single part, when one player wins, it goes to a piece of code where it stops the current background music and plays winning music. I need to somehow "pause" everything except for the music for about 4 seconds then resume. Is there any easy way to accomplish this?
Donald8274
 
Posts: 9
Joined: Thu Jun 06, 2013 8:00 am

Re: [PyGame] Help on a time issue

Postby octopez » Thu Jun 06, 2013 8:31 am

Without seeing, how your code is organized, we only can give general advise.

You have to keep track of the game state. When the state changes, you have to change the music as well.
Greetings and all the best,
Octopez

Strange women lying in ponds distributing swords is no basis for a system of government.
User avatar
octopez
 
Posts: 25
Joined: Fri Feb 08, 2013 11:26 pm

Re: [PyGame] Help on a time issue

Postby Donald8274 » Thu Jun 06, 2013 8:41 am

My code is a big mess but I'll post the important part.

Code: Select all
if p1Score == 5 or p2Score == 5:
        bgm.stop()
        win.play()
        time.delay(5000)
        p1Score, p2Score = 0, 0
        bgm.play(-1)

I tried it with the delay but it just pauses the whole code (as I thought it would)
Donald8274
 
Posts: 9
Joined: Thu Jun 06, 2013 8:00 am

Re: [PyGame] Help on a time issue

Postby Donald8274 » Thu Jun 06, 2013 9:24 am

Nevermind, I realized it was the sound file that was the issue, I'm sorry for wasting time on this. Thank you though for responding.
Donald8274
 
Posts: 9
Joined: Thu Jun 06, 2013 8:00 am

Re: [PyGame] Help on a time issue

Postby Mekire » Thu Jun 06, 2013 10:18 am

Well again you haven't given much code to tell much here but I'll say that using time.delay() to do this is not good practice in general. You need to (generally) do this in a way that allows screen elements and game logic to continue to update (even if you don't intend for either to change during this time period).

-Mek
User avatar
Mekire
 
Posts: 1126
Joined: Thu Feb 07, 2013 11:33 pm
Location: Asakusa, Japan


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron