python - 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,我正在尝试将背景填充为白色。
解决方案
您的可变减速已关闭。
您将其声明为
GameDisplay=pygame.display.set_mode((width,height))
但是你用它来称呼它
gameDisplay.fill(White)
将其更改为GameDisplay.fill(White)
,您将被设置。
推荐阅读
- python - 矩阵(2x1)中的数字数组而不改变其形状
- python - 在 python 中将 Yes 转换为 1 和 No 转换为 0
- apache-kafka - kafka集群支持多少个stream
- javascript - 我可以将字符串传递给 javascript 函数并将其用作对象的属性吗?
- python - python正则表达式 - 在文件中搜索模式
- ms-access - Filtering a MS-Access recordset based on records in another recordset
- git - 如何删除链接存储库中的 git 远程标签?
- amazon-web-services - EBS 中的使用量和可用量有什么区别
- c - 以正确的方式使用 long long 数据类型
- json - 还需要带有其键的 jq 输出