首页 > 解决方案 > gameDisplay.fill(White) NameError: name 'gameDisplay' 没有定义?

问题描述

我收到了这个错误

gameDisplay.fill(White) NameError: name 'gameDisplay' is not defined

我的代码

    import pygame,sys
from pygame.locals import *


pygame.init()

width=800
height=600
TITLE="test"
FrameRate=30

#images
ball=pygame.image.load("Red_Ball.png")

#Color
Black=(0,0,0)
White=(255,255,255)
#fonctions
def Ball(x,y):
    gameDisplay.blit(ball,(x,y))


GameDisplay=pygame.display.set_mode((width,height))
pygame.display.set_caption(TITLE)
clock=pygame.time.Clock()



x=width*0.45
y=height*0.8


while True:

    for event in pygame.event.get():
        if event.type==quit :
            pygame.quit()
            quit()
    gameDisplay.fill(White)
    Ball(x,y)
    pygame.display.flip()
    clock.tick(FrameRate)

这里有什么问题?我得到了 python 3,我正在尝试将背景填充为白色。

标签: pythonpython-3.xpygame

解决方案


您的可变减速已关闭。

您将其声明为

GameDisplay=pygame.display.set_mode((width,height))

但是你用它来称呼它

gameDisplay.fill(White)

将其更改为GameDisplay.fill(White),您将被设置。


推荐阅读