我确实运行了代码,突然消失了,我遇到了这个错误,该怎么办?我该如何为背景图像选择合适的尺寸?

发布于 2025-02-02 20:41:11 字数 661 浏览 3 评论 0原文

我确实运行了我的代码,但突然消失了,我遇到了一个错误,说“ screat.fill(background_img)typeerror:无效的颜色参数” 在此处输入图像描述。 我也不知道如何调整我要用于屏幕背景的背景图像的大小


pygame.init()
background_img = pygame.image.load("C:\\Users\\lenovo\\Pictures\\maxresdefault.jpg")
(width, height) = (800, 800)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Hop Along')
screen.fill(background_img)

pygame.display.update()

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            pygame.quit()

I do run my code, but its suddenly gone, and I get this error saying "screen.fill(background_img)TypeError: invalid color argument"enter image description here.
I dont also know how to resize the background image that i want to use for my screen background


pygame.init()
background_img = pygame.image.load("C:\\Users\\lenovo\\Pictures\\maxresdefault.jpg")
(width, height) = (800, 800)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Hop Along')
screen.fill(background_img)

pygame.display.update()

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            pygame.quit()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世界如花海般美丽 2025-02-09 20:41:11

您不能带有图像的显示。您必须图像:

screen.fill(backgrough_img)

screen.blit(background_img, (0, 0))

如果背景图像的大小与窗口不同,则可以使用

background_img = pygame.image.load("C:\\Users\\lenovo\\Pictures\\maxresdefault.jpg")
scaled_background = pygame.transform.smoothscale(background_img, (width, height))
screen.blit(scaled_background, (0, 0))

You cannot fill the display with an image. You must blit an image:

screen.fill(background_img)

screen.blit(background_img, (0, 0))

If the background image is a different size than the window, you can use pygame.transform.smoothscale to scale the image:

background_img = pygame.image.load("C:\\Users\\lenovo\\Pictures\\maxresdefault.jpg")
scaled_background = pygame.transform.smoothscale(background_img, (width, height))
screen.blit(scaled_background, (0, 0))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文