-1

I'm trying to make a day/night feature for my game where every 10 minutes the background changes, but when I run it it just crashes on startup. Here's the buggy code.

bg = pygame.image.load("bg.png")
bgg = pygame.image.load("bbg.png")

def bg1():
    screen.blit(bg, (0, 0))

def bbg1():
    screen.blit(bbg, (0, 0))

def fbg():
    bg1()
    pygame.time.wait(10000)
    bbg1()


screen.fill((0,0,0))
fbg()

I have the screen.fill((0,0,0)) because there is a rect there as well which moves around.

  • The wait command freezed the execution of your app for 10 minutes.. i dont think this is what you want... – Mailerdaimon Feb 11 '15 at 10:55
  • 2
    Is the 'crash' just the game waiting for 10 minutes? – Matthew Franglen Feb 11 '15 at 10:56
  • 1
    See: http://stackoverflow.com/questions/18839039/what-are-the-best-approaches-to-wait-some-time-in-pygame-and-python-code-in-gene – Mailerdaimon Feb 11 '15 at 10:56
  • You may want to take a look here: [Move an object every few seconds in Pygame](https://stackoverflow.com/questions/23368999/move-an-object-every-few-seconds-in-pygame) – sloth Feb 11 '15 at 11:23

1 Answers1

1

Your problem is that the pygame.time.wait call just stops the execution of the current thread for 10,000 milliseconds. You need to have another thread that actually runs the game.

The documentation states that:

pygame.time.wait()

Will pause for a given number of milliseconds. This function sleeps the process to share the processor with other programs. A program that waits for even a few milliseconds will consume very little processor time. It is slightly less accurate than the pygame.time.delay() function.

Community
  • 1
  • 1
Matthew Franglen
  • 4,441
  • 22
  • 32