退出pygame
时遇到了一些问题当我试图关闭窗口时,它告诉我视频系统没有初始化 我不知道如何在这里打包图片,抱歉。错误发生在标有“!!!!!”的行中
这是我的代码
# PreTitleScreen
# cited from http://programarcadegames.com/python_examples/
# f.php?file=sprite_collect_blocks.py
# the framework of this file are mostly cited from the above address
import pygame, configure, instructions, game
# constant
PTS_WIDTH = 1024 # pre screen width
PTS_HEIGHT = 768 # pre Screen height
class TitleScreen():
def __init__(self):
self.c = configure.Configure()
done = False
pygame.init()
clock = pygame.time.Clock()
while not done:
self.screen = pygame.display.set_mode([PTS_WIDTH,PTS_HEIGHT])
pygame.display.set_caption("Bomberman")
# import background image
bgImagePath = self.c.IMAGE_PATH + "titleScreen.png"
bgImage = pygame.image.load(bgImagePath).convert()
bgImage = pygame.transform.scale(bgImage,(PTS_WIDTH,PTS_HEIGHT))
self.screen.blit(bgImage,[0,0])
pygame.mixer.music.load(self.c.AUDIO_PATH + "title.mid")
pygame.mixer.music.play()
# pygame.display.flip()
notValidOp = False
# under valid control mode
while not notValidOp:
print("enter the inner loop")
# get mouse position
pos = pygame.mouse.get_pos()
# testCode
for event in pygame.event.get():
# deal with the exit
print('event.type', event.type)
if event.type == pygame.QUIT:
print("quit")
notValidOp = not notValidOp
done = not done
elif event.type == pygame.MOUSEBUTTONDOWN:
print("get from general",pos)
if self.inBoundary(pos[0],pos[1],25, 500, 250, 550):
self.playGame("S")
elif self.inBoundary(pos[0],pos[1],25, 550, 250, 600):
self.playGame("M")
elif self.inBoundary(pos[0],pos[1],25, 600, 250, 650):
self.instructions()
elif self.inBoundary(pos[0],pos[1],25, 650, 250, 700):
print("high Score")
print("get from score",pos)
elif self.inBoundary(pos[0],pos[1],40, 700, 250, 750):
print("exit")
done = not done
notValidOp = not notValidOp
# Go ahead and update the screen with what we've drawn.
pygame.display.flip() # !!!!!!!!!!!!!!
# Limit to 60 frames per second
clock.tick(self.c.FPS)
def inBoundary(self,x0,y0,x1,y1,x2,y2):
if ((x1 <= x0 <= x2) and (y1 <= y0 <= y2)):
return True
return False
def instructions(self):
instructions.Instructions()
def playGame(self,mode):
game.Game(mode)
# pygame.init()
# test Code below
TitleScreen()
答案 0 :(得分:0)
可能不是正确的问题,但我很确定你必须退出游戏(在你的if event.type == QUIT:
部分),如下:
if event.type == QUIT:
pygame.quit()
sys.exit()
此外,如果您没有import pygame.locals as *
,则可能必须使用pygame.locals.QUIT
而不是QUIT
。
答案 1 :(得分:0)
这通常在您拨打pygame.display.flip()
然后再致电pygame.display.flip()
时发生。
您没有显示完整的代码,但请确保在致电pygame.quit()
后不要致电public class MediaTypeDelegatingHandler: DelegatingHandler
{
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.Headers.Accept.Contains(MediaTypeWithQualityHeaderValue.Parse("application/json")) == false)
{
return request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
}
return await base.SendAsync(request, cancellationToken);
}
}
。