微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

了解 pygame 背景

如何解决了解 pygame 背景

如何在pygame中制作白色背景?我在找出使背景变白的正确代码以及将其放入代码的确切位置时遇到问题。

解决方法

如何在pygame中制作白色背景?

当调用 pygame.display.set_mode() 时,pygame.Surface 与显示相关联。更新后,在此Surface 上绘制的所有内容都可以在显示屏上看到。 fill 显示为白色的表面

screen = pygame.display.set_mode((500,500))

# [...]

screen.fill("white")

# [...]

pygame.display.flip()

在我的代码中的确切位置。

典型的 PyGame 应用程序循环必须:

示例:

import pygame

pygame.init()
screen = pygame.display.set_mode((500,500))
clock = pygame.time.Clock()

run = True
while run:
    clock.tick(60)
    
    # handel events
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False 

    # update game         

    # clear screen with white color
    screen.fill("white")

    # draw scene
    # [...]
    
    # update diesplay
    pygame.display.flip()

pygame.quit()
exit()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。