在OSX上使用Pygame进行错误的全屏分辨率

时间:2017-03-04 17:11:33

标签: python macos pygame

我正在尝试使用python + pygame为OSX创建一个全屏应用,但请注意,无法以正确的分辨率创建显示。

import pygame, logging, sys
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

pygame.init()
screen_info = pygame.display.Info()
flags = pygame.DOUBLEBUF | pygame.HWSURFACE | pygame.FULLSCREEN
screen = pygame.display.set_mode((0, 0), flags)
done = False
rect_w = 60
rect_h = 60
x = (screen_info.current_w / 2) - (rect_w / 2)
y = (screen_info.current_h / 2) - (rect_h / 2)

logging.debug('Screen res is ' + str(screen_info.current_w) + 'x' + str(screen_info.current_h))
logging.debug('Center is ' + str(x) + 'x' + str(y))

while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
            done = True

        color = (255, 100, 0)
        pygame.draw.rect(screen, color, pygame.Rect(x, y, rect_w, rect_h))

        pygame.display.flip()

当我运行此代码时,我可以看到我的矩形不在屏幕中间。经过一些调试后,应用程序似乎在顶部和底部留下空格。此外,右侧被切断。

我在这里出错了什么?

0 个答案:

没有答案