问题
def monkey_bomb(self):
self.image = pygame.image.load("./images/monkey_bomb.png")
delay(1000)
self.image = pygame.image.load("./images/monkey.png")
This is one of the method in my player sprite class
so what I wanted to do is that when the player sprite hits a bomb, it will show a explosion effect, then go back to the normal image for the player sprite
but seems like pygame doesn't support the whole 'delay' thing, how do I do this in another way?
回答1:
You don't want to delay in the middle of the game: that would freeze everything. Instead, you should load both images in advance, then in the situation where you want to switch to another you:
- Save the current time, either from e.g.
time.time()or a frame counter. - Swap the images. Either literally
a, b = b, aor change a flag that says which image to display. - When sufficient time has passed (e.g.
time.time() > saved_time + 1), you swap them back.
Where and how you do the last step depends on how the rest of your code is structured.
来源:https://stackoverflow.com/questions/23982287/is-it-possible-to-show-an-image-for-a-while-and-then-change-it-back