pygame does not blit unless I call pygame.event.get()

徘徊边缘 提交于 2019-12-10 20:17:52

问题


After crashing my head against the monitor for 2 hours I realised that:

display.blit(mypic, posx, posy)
pygame.display.update()

would just not work (i.e. wouldn't blit anything on the screen) unless I call:

pygame.event.get()

Is this the weirdest bug on earth, or am I missing something?

I'm running pygame on python 2.7, mac os high sierra, and yes I would be the least surprised if this was due to the goddam incompatibility between pygame and mac os.

Any hint about what is going wrong here?

Example code:

import pygame
winWidth = 800
winHeight = 600
posx = 200; posy = 200
mypic = pygame.image.load("path_to_my_picture.jpg")
COL_BACKGROUND = (255,255,255)

DISPLAYSURF = pygame.display.set_mode((winWidth, winHeight))
pygame.init()
display.fill(COL_BACKGROUND)
display.blit(mypic, posx, posy)

# only including the following line it will blit the picture:
# pygame.event.get()

pygame.display.update()

回答1:


I'm not 100% sure how it works with mac but I am assuming it is similar to windows in that if you don't call pygame.event.get() regularly the operating system thinks that the window has stopped responding and no longer updates it.

This is mentioned under pygame.event.pump() in the events page of the Pygame documentation

For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system. If you are not using other event functions in your game, you should call pygame.event.pump() to allow pygame to handle internal actions.



来源:https://stackoverflow.com/questions/48450396/pygame-does-not-blit-unless-i-call-pygame-event-get

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!