问题描述
所以我开始为学校项目编写游戏,目前遇到了 <div id="agreement">
<button class="agree" onclick="ChangeContent()">I agree</button>
<div class="btn--no-schedule">
<a href="#" class="schedule-agreement">SCHEDULE</a>
</div>
</div>
event.type
的问题。
这是我的代码。运行它时会打开一个窗口,但它保持完全黑色,不显示背景颜色或精灵。我尝试用 print() 命令查明问题,以查看代码在哪一行停止工作。每个,除了最后一个打印命令被执行,这让我相信 While 循环是我的问题的原因。
KEYDOWN
这是控制台输出:
import pygame
from pygame.locals import *
print("Import complete")
WIDTH = 640
HEIGHT = 480
TITLE = "Tales of Tesbold"
print("Window complete")
Tesbold = Actor("tesbold.png") #Sprites vordeFinition
Tesbold.x = 200
Tesbold.y = 100
print("Tesbold complete")
wechsel = True
def draw(): #Hintergrund und alle Sprites
screen.clear()
screen.fill((200,200,200))
Tesbold.draw()
print("Draw Screen complete")
while True:
for event in pygame.event.get():
if event.type == quit:
sys.exit()
if event.type == KEYDOWN:
if(event.key == K_RIGHT):
Tesbold.x += 10
print("While Loop complete")
有人能告诉我我做错了什么让它不再起作用了吗?
解决方法
Python 区分大小写。事件类型枚举器全部用大写字母书写。请参阅 pygame.event
模块:
if event.type == quit:
if event.type == QUIT:
pygame.quit()
是一个函数,用于取消初始化所有 pygame 模块。