我跟随了一个turtorial,在那里我正在使用pygame创建游戏。我刚开始,我已经有问题了。它说它很难找到图像。它是这样说的:
C:\Users\Patryk\AppData\Local\Programs\Python\Python39\python.exe:
can't open file ''
C:\Users\Patryk\PycharmProjects\PePeSza-Game\main.py: [Errno 2]
我试着寻找有同样问题的人,但找不到我问题的答案。以下是完整的代码:
import pygame
pygame.init()
# Game window
screen_width = 800
screen_height = 640
lower_margin = 100
side_margin = 300
screen = pygame.display.set_mode((screen_width,screen_height))
screen = pygame.display.set_caption(('Level editor'))
# Importing images
bg_img = pygame.image.load('./bg.png')
# Create function for drawing background
def draw_bg():
screen.blit('bg_img', (0, 0))
# Mainloop
run = True
while run:
draw_bg()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.display.update()
pygame.quit()
在代码中需要做两件事
完整代码:
相关问题 更多 >
编程相关推荐