运行此应用程序时出错:
import pygame,sys
from pygame.locals import *
pygame.init()
mainClock = pygame.time.Clock()
windowsSurface = pygame.display.set_mode((600,500))
pygame.display.set_caption('move')
player = pygame.Rect(300,100,40,40)
player_image = pygame.image.load('bb8.jpg')
playerStretchedImage = pygame.transform.scale(player_image,(40,20))
backgroundimage = pygame.image.load('map.png')
images = []
moveright = False
moveleft = False
moveup = False
movedown = False
movespeed = 6
WHITE = (255,255,255)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key== K_LEFT or event.key == K_a:
moveright=False
moveleft=True
if event.key==K_RIGHT or event.key == K_d:
moveleft = False
moveright = True
if event.key==K_UP or event.key == K_w:
movedown = False
moveup = True
if event.key==K_DOWN or event.key == K_s:
moveup = False
movedown = True
if event.type == KEYUP:
if event.key==K_ESCAPE:
pygame.quit()
sys.exit()
if event.key== K_LEFT or event.key == K_a:
moveleft=False
if event.key==K_RIGHT or event.key == K_d:
moveright = False
if event.key==K_UP or event.key == K_w:
moveup = False
if event.key==K_DOWN or event.key == K_s:
movedown = False
windowsSurface.fill(WHITE)
if movedown and player.bottom < 600:
player.top += movespeed
if moveup and player.top> 0:
player.top-= movespeed
if moveleft and player.left > 0:
player.left-= movespeed
if moveright and player.right < 500:
player.right += movespeed
for image in images:
windowsSurface.blit(image,backgroundimage)
windowsSurface.blit(playerStretchedImage,player)
pygame.display.update()
mainClock.tick(40)
我希望BB8在map.png中移动,但它显示错误让我感到奇怪: 错误在这里:
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00002908 (most recent call first):
然后停止。 它看起来像一个系统错误。 请给出一些建议。
我正在使用python 3.5并在visual studio code
上的cmd.code上运行