Pygame 在 Mac OSX Mojave 上的绘图不一致

Inconsistent drawing in Pygame on Mac OSX Mojave

我断断续续地制作一款口袋妖怪风格的游戏已有一个月左右的时间,最近刚刚更新到 Mojave 以查看新功能。

更新后,我注意到我的游戏存在一些小问题,其中一个具体问题是 HP 条的绘制方式与 High Sierra 不同。之前它的宽度会逐渐减小,但现在程序只是冻结动画播放的时间,然后跳到动画的结尾。为什么会发生这种情况?

我现在知道 Pygame 在 Mojave 中存在绘图问题(据说是由于新的黑暗模式),但我还没有看到任何人描述只有 的情况他们的程序的一小部分 受到了影响- 大多数报告来自 18 年并抱怨 完全没有绘图

无论如何,这是我的 HP 条动画代码:

def changeHP(barPos, maxHP, startHP, dif): #This function displays the animation for hp loss/gain
    timer = pygame.time.Clock()
    for i in range(int(dif*100/maxHP)):
        difPer = (maxHP*i/100)
        if startHP - difPer <= maxHP/5:
            color = Color(255, 0, 0, 255)
        elif startHP - difPer <= maxHP/2:
            color = Color(255, 255, 0, 255)
        else:
            color = Color(0, 255, 0, 255)
        pygame.draw.rect(screen, Color(255, 255, 255, 255), (barPos[0], barPos[1], 144, 9))
        pygame.draw.rect(screen, color, (barPos[0], barPos[1], ((startHP - difPer)/maxHP) * 144, 9))
        pygame.display.update()
        timer.tick(60)

抱歉,如果某些值看起来令人费解,这是一项正在进行的工作。

嗯,我没想到这真的有用,但它确实有用。

我在循环中添加了一个事件队列检查,然后一切恢复正常。

这是我更新后的代码:

def changeHP(barPos, maxHP, startHP, dif): #This function displays the animation for hp loss/gain
timer = pygame.time.Clock()
for i in range(int(dif*100/maxHP)):
    difPer = (maxHP*i/100)
    if startHP - difPer <= maxHP/5:
        color = Color(255, 0, 0, 255)
    elif startHP - difPer <= maxHP/2:
        color = Color(255, 255, 0, 255)
    else:
        color = Color(0, 255, 0, 255)
    pygame.draw.rect(screen, Color(255, 255, 255, 255), (barPos[0], barPos[1], 144, 9))
    pygame.draw.rect(screen, color, (barPos[0], barPos[1], ((startHP - difPer)/maxHP) * 144, 9))
    pygame.display.update()
    timer.tick(60)
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()