ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

除非我调用pygame.event.get(),否则pygame不会变色

2019-10-25 11:59:40  阅读:199  来源: 互联网

标签:pygame event-handling python macos


将我的头撞到显示器上两个小时后,我意识到:

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

除非我打电话:否则将无法正常工作(即不会在屏幕上涂抹任何东西)

pygame.event.get()

这是地球上最怪异的错误,还是我错过了一些东西?

我在python 2.7,mac os high sierra上运行pygame,
是的,如果这是pygame和mac os之间的不兼容,那我将最不惊讶.

关于这里出什么问题的任何提示吗?

示例代码:

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()

解决方法:

我不是100%知道它如何与mac一起工作,但我假设它与Windows相似,因为如果您不定期调用pygame.event.get(),操作系统会认为该窗口已停止响应并且不再更新它.

Pygame文档的事件页面中的pygame.event.pump()下对此进行了提及

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.

标签:pygame,event-handling,python,macos
来源: https://codeday.me/bug/20191025/1928383.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有