這是我創建遊戲的代碼。當我嘗試運行它時,它一直說名稱「寬度」爲 未定義。我對此很陌生,所以請在回答我的問題時儘量簡單。謝謝:)Python NameError:name'width'is not defined
# 1 - Import library
import pygame
from pygame.locals import *
# 2 - Initialize the game
pygame.init()
width, height - 640, 480
screen-pygame.display.set_mode((width, height))
# 3 - Load Images
player - pygame.images.load("resources/images/dude.png")
# 4 - keep looping through
while 1:
# 5 - clear the screen before drawing it again
screen.fill(0)
# 6 - draw the screen elements
screen.blit(player, (100,100))
# 7 - update the screen
pygame.display.flip()
# 8 - loop through the events
for event in pygame.event.get():
# check if the event is the X button
if event.type--pygame.QUIT:
# if it is quit the game
pygame.quit()
exit(0)
這個問題似乎是題外話,因爲它是關於一個錯字('-'而不是'=')。 – Doorknob
作業是'=',而不是'-' –
可能的'寬度,高度= 640,480'會有幫助嗎? –