没有在pygame中加载图像



所以我尝试了很多事情(首先,代码是基于OOP的,但我更改了它,篡改了变量,但没有用(,我不知道为什么我的图像(代码中的Hero.png(没有显示。我对python/pygame有点陌生,所以这一定是个愚蠢的错误。谢谢,这是代码。它还不是一个完整的代码。

Import pygame
pygame.init()
winX = 720
winY = 1280
win = pygame.display.set_mode([winY, winX])
GameRun = True
clock = pygame.time.Clock()
HeroSprite = pygame.image.load('Hero.png')
pygame.display.set_caption("Game thingy")
bg = pygame.image.load('bg.jpg')
HeroX = winX / 2
HeroY = winY - 100
vel = 5
def redrawGameWindow(win, HeroX,HeroY):
win.blit(bg, (0,0))
win.blit(HeroSprite, (HeroX, HeroY))
pygame.display.update()
while GameRun:
clock.tick(60)
pressed = pygame.key.get_pressed()
if pressed[pygame.K_LEFT]:
HeroX -= vel if HeroX > 20 else 0
elif pressed[pygame.K_RIGHT]:
HeroX += vel if HeroX < winX - 20 else 0
for event in pygame.event.get():
if event.type == pygame.QUIT:
GameRun = False
redrawGameWindow(win, HeroX, HeroY)
pygame.quit()

您已经交换了winXwinY:

winX = 720
winY = 1280
win = pygame.display.set_mode([winY, winX])

所以英雄的初始位置不在窗口中:

HeroX = winX / 2
HeroY = winY - 100

交换窗口大小的变量:

winX = 1280
winY = 720
win = pygame.display.set_mode([winX, winY])

相关内容

  • 没有找到相关文章

最新更新