PyGame Not Quiting - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Game Development (https://python-forum.io/forum-11.html) +--- Thread: PyGame Not Quiting (/thread-28368.html) |
PyGame Not Quiting - KieranPage - Jul-16-2020 Hi ive recently started coding something in pygame and have been following along with a set of tutorial but recently whenever you hover over the close button in the pygame window it just freaks out and closes I have recently converted it from python to visual basic If it helps here is my code: import pygame as pg import random from Settings import * class Game: def __init__(self): #Initialases Game window pg.init() pg.mixer.init() self.screen= pg.display.set_mode ((width, height)) pg.display.set_caption(Title) self.clock=pg.time.Clock() self.running = True def new (self): #Starts game upon death self.all_sprites = pg.sprite.Group() self.run def run(self): #Game Loop self.playing = True while self.playing: self.clock.tick (fps) self.events() self.update() self.draw() def update(self): #Game loop Update self.all_sprites.update() def events(self): #Game loop events for event in pg.event.get(): if event.type == pg.QUIT: if self.playing: self.playing = False self.running=False def draw(self): #Game loop draw self.screen.fill(Black) self.all_sprites.draw(self.screen) pg.display.flip() def show_start_screen(self): #Show The start Screen pass def show_go_screen(self): #Shows The Game Over Screen pass g = Game() g.show_start_screen() while g.running: g.new() g.show_go_screen() pg.quit() #And here is my Settings Script That it imports Title = "Platform Adventure" width = 480 height = 600 fps = 60 #Colours White = (255, 255, 255) Black = (0, 0, 0) Red = (255, 0, 0) Light_Blue = (0, 255, 255) RE: PyGame Not Quiting - Knight18 - Jul-16-2020 Your code just looks rather weird. I mean the part related to "quitting" and your placement of while loops. You lack a sys.exit() statement too. I really think you read this article and focus on how the quitting was handled. It's a bit too long to explain here. Pygame Tutorial. RE: PyGame Not Quiting - KieranPage - Jul-16-2020 Okay thanks |