python - python 3.6.5 中的 pygame 中没有显示图像

标签 python python-3.x image pygame python-3.6

我在 Win32 上使用 Python 3.6.5 中的 Pygame,但我的 MarioGround.png 没有显示。我还有两张图片,其中一张正在工作,另一张没有。我也没有收到任何错误。这是我的完整代码(待处理):

import pygame

pygame.init()

black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
blue = (0,0,255)
sky_blue = (0,150,225)
green = (0,255,0)

displayWidth = 800

displayHeight = 600
#Final :- pygame.display.set_mode((1365, 1050))
gameDisplay = pygame.display.set_mode((displayWidth,displayHeight))
pygame.display.set_caption('Super Mario')
clock = pygame.time.Clock()


crashed = False

timeOut = False

Quit = False

#50,75
marioStanding = pygame.image.load('Super_Mario_Standing2.png').convert()
marioStanding = pygame.transform.scale(marioStanding, (displayWidth//16,displayHeight//8))

ground = pygame.image.load('MarioGround.png')

def Stand(mx,my):
    gameDisplay.blit(marioStanding,(mx,my))

mx = (displayWidth * 0.45)
my = (displayHeight * 0.8)

def makeGround(gx,gy):
    gameDisplay.blit(ground,(gx,gy))

gx = (displayHeight * 0.45)
gy = (displayWidth * 0.8)

while not crashed and not timeOut and not Quit:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            Quit = True

    print (event)

    gameDisplay.fill(sky_blue)
    makeGround(gx,gy)
    Stand(mx,my)

    pygame.display.update()
    clock.tick(24)

pygame.quit()
quit()

我的 Super_Mario_Standing2.png 出现了,但 MarioGround.png 没有出现。这里是它们的链接:MarioGround.png:https://drive.google.com/open?id=1Jz7zTI5Cukv8fXlmyOEkwJTOTkuxIGUP

Super_Mario_Standing.png:https://drive.google.com/open?id=1eUDAin-BUUzi6l-DgxHrf9v8JP8kdAPt

谢谢!!!

最佳答案

您混淆了 displayWidthdisplayHeight 变量,这意味着 gy 变量为 640(屏幕下方)。只需交换它们(另外,这里不需要括号):

gx = displayWidth * 0.45
gy = displayHeight * 0.8

关于python - python 3.6.5 中的 pygame 中没有显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52105116/

相关文章:

python - 相关热图在 Python 中将值转换为 nan

python - 在python程序中使用DBus

python - 为什么 Datetime 的 `.timestamp()` 方法返回 `OSError: [Errno 22] Invalid argument` ?

python - 为什么我的 glob.glob 循环没有遍历文件夹中的所有文本文件?

python - 使用排序列有效地从 Pandas 数据框中选择行

html - 固定图像尺寸

python - Python 中的所有变量都是类的某个对象吗?还是他们自己上课?

python - 为什么 if 语句在 ElementTree 解析中不起作用?

ios - 如何增加声音文件(如uiimagefile)的值

c++ - 简单的图像分析