【问题标题】:Can't load image to pygame display无法将图像加载到 pygame 显示
【发布时间】:2018-10-02 21:30:59
【问题描述】:

我的图像不会显示在屏幕上,但我没有收到任何错误。我查了一下,没有找到适合我的解决方案。

代码:

import pygame

pygame.init()
sw = 500
sh = 500
win = pygame.display.set_mode((sw,sh))
fps = pygame.time.Clock()
x = (sw * 0.3)
y = (sh * 0.95)
# also tried just convert() and no convert at all
player = pygame.image.load('SH.png').convert_alpha()
white = (255, 255, 255)
def Player(x, y):
    win.blit(player, (x, y))

dead = False

run = True
while not dead:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            dead = True
    win.fill(white)
    Player(x, y)

    pygame.display.update()
    fps.tick(60)

pygame.quit()

【问题讨论】:

  • 如果你尝试不同的图像,它会起作用吗?
  • 对我自己的图像有用,尽管图像几乎不在显示的窗口底部。你的图像有多大?建议您将您正在使用的图像文件上传到imgur,然后edit 您的问题并添加一个链接(因为这听起来可能是问题所在)。
  • 我的猜测是您的图像在顶部有很多空白/透明空间,并且由于您在屏幕底部附近对其进行 blitting,因此它不可见,因为不透明区域位于屏幕下方.但是,如果没有您的图片,我无法验证,因此请将其添加到问题中。
  • 我已经弄清楚了。很抱歉在这个问题上浪费时间:/

标签: python python-3.x image pygame


【解决方案1】:

我把图片缩小了,因为它太大而且不在屏幕上。

这解决了问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多