我的精灵图像没有显示在 pygame 窗口中。这可能很简单,但我不明白为什么它没有显示。我对编程很陌生,所以这可能是我不明白这一点的原因。这是我在课堂上做错了什么吗?这是我的代码:
import pygame, sys
from pygame.locals import *
windowwidth = 600
windowheight = 600
WALLWIDTH = 30
WALLHEIGHT = 30
PLAYERWIDTH = 20
PLAYERHEIGHT = 20
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
LIMEGREEN = (50, 205, 50)
class Player(pygame.sprite.Sprite):
def __init__(self, x, y):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('Green circle png.png')
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
def changespeed(self, x, y):
self.change_x = x
self.change_y = y
def update_pos(self, x, y):
old_x_pos = self.rect.x
new_x_pos = old_x_pos + self.change_x
self.rect.x = new_x_pos
old_y_pos = self.rect.y
new_y_pos = old_y_pos + self.change_y
self.rect.x = new_y_pos
def main():
pygame.init()
thescreen = pygame.display.set_mode((windowwidth, windowheight))
pygame.display.set_caption('Maze Game')
thescreen.fill((BLACK))
mainclock = pygame.time.Clock()
running = True
while running == True:
for event in pygame.event.get():
if event.type == QUIT:
running = False
if event.type == KEYDOWN:
if (event.key == K_UP or event.key == K_w):
Player.changespeed = (-3, 0)
elif (event.key == K_DOWN or event.key == K_s):
Player.changespeed = (3, 0)
elif (event.key == K_LEFT or event.key == K_a):
Player.changespeed = (0, -3)
elif (event.key == K_RIGHT or event.key == K_d):
Player.changespeed = (0, 3)
if event.type == KEYUP:
if (event.key == K_UP or event.key == K_w):
Player.changespeed = (0, 0)
elif (event.key == K_DOWN or event.key == K_s):
Player.changespeed = (0, 0)
elif (event.key == K_LEFT or event.key == K_a):
Player.changespeed = (0, 0)
elif (event.key == K_RIGHT or event.key == K_d):
Player.changespeed = (0, 0)
mainclock.tick(60)
pygame.display.update()
pygame.quit()
if __name__ == '__main__':
main()