python3 pygame load图片不显示_关于pygame image.load函数的问题
问题如下,我有一个文件夹,我从中获取buncha图像,有许多(30-40)使用pygame.image.load函数(需要它们作为我游戏的精灵),它们与我的python文件在不同的目录中,例如,我的python游戏在“C:\ PythonProjects\Programs\Pygame2.py”中,图片在“C:\ Users\user\Documents\Generic game”中我试着到处搜索
问题如下,我有一个文件夹,我从中获取buncha图像,有许多(30-40)使用pygame.image.load函数(需要它们作为我游戏的精灵),它们与我的python文件在不同的目录中,例如,我的python游戏在“C:\ PythonProjects\Programs\Pygame2.py”中,图片在“C:\ Users\user\Documents\Generic game”中
我试着到处搜索,显然你必须复制整个目录路径这样加载每个?(pygame.image.load(“C:/Users/user/Documents/Le game/BG.jpg”)
花时间帮忙的大建议<3
这是我的代码供参考(结构很混乱,但一旦我发现这个问题,我会改变周围的东西):
import pygame
pygame.init()
win = pygame.display.set_mode((800, 700))
pygame.display.set_caption("Potato ultra")
BG = pygame.image.load("C:/Users/user/Documents/Generic game/BG.jpg")
walkRight = [#need to use pygame.image.load function for images here]
walkLeft = [#Same case]
SW = 500
x = 0
y = 480
width = 64
height = 64
vel = 20
isJump = False
JumpCount = 10
def redrawGameWindow():
win.blit(BG, (0,0))
pygame.draw.rect(win, (0, 200, 0), (x, y, width, height))
pygame.display.update()
run = True
while run:
pygame.time.delay(50)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and x > 0:
x -= vel
if keys[pygame.K_RIGHT] and x < SW - width:
x += vel
if not isJump:
if keys[pygame.K_UP] and y > 0:
y -= vel
if y < 0:
y = 0
if keys[pygame.K_DOWN] and y < SW - vel:
y += vel
if y > 436:
y = 436
if keys[pygame.K_SPACE]:
isJump = True
else:
if JumpCount >= -10:
y -= (JumpCount * 4)
if y < 0:
y = 0
JumpCount -= 2
else:
isJump = False
JumpCount = 10
redrawGameWindow()
pygame.quit()
更多推荐
所有评论(0)