你好我对pygame有点新,我写了这段代码:
import sys, pygame
pygame.init()
screen = pygame.display.set_mode((800, 368))
background = pygame.image.load("background.png")
background.convert()
screen.blit(background, (0, 0))
ball = pygame.image.load("ball.bmp")
ballrect = ball.get_rect()
player1 = pygame.image.load("player1.png")
player1rect = player1.get_rect()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1]
screen.blit(ball, ballrect)
screen.blit(player1, player1rect)
pygame.display.update()
但是当我打开它时它只是说
File "C:\Users\User\Documents\Pong\pong.py", line 20, in <module>
ballrect = ballrect.move(speed)
NameError: name 'speed' is not defined
请帮助我,我需要它。我无法自己解决这个问题。