having problems with my pygame event loop. it gets to the event handling but it cant seem to cope with checking the event type without hanging and crashing.
import pygame
import asyncio
import threading
pygame.init()
pygame.font.init() # just in case :3
# jfont = pygame.font.Font("VCR_OSD_MONO_1.001.ttf", 14)
screenSurface = pygame.display.set_mode((400,400))
clock = pygame.time.Clock()
gameState = "initing"
songname = ""
accuracy = 0
statesToTitleDict = {
"initing":"loading...",
"menu":"Menu",
"playing":"In Song: %s, accuracy %.1f%%",
"closing":"shutting down...",
}
def textSurfaceFabricator(text, color):
return jfont.render(text,False,color)
async def titleUpdater():
while gameState != "closing":
if gameState != "playing":
pygame.display.set_caption(statesToTitleDict[gameState])
else:
pygame.display.set_caption(statesToTitleDict[gameState] % (songname, accuracy))
pygame.display.set_caption(statesToTitleDict["closing"])
def titleUpdaterInit():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
asyncio.ensure_future(titleUpdater())
loop.run_forever()
titupdathread = threading.Thread(target=titleUpdaterInit)
titupdathread.start()
while gameState != "closing":
print("loop")
for event in pygame.event.get():
print(event)
if event.type == pygame.QUIT:
gameState = "closing"
pygame.quit()
else:
print(event)
pass
print("after event handling")
clock.tick(60)