Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pygame built-in automatic pause?

Tags:

python

pygame

I just recently learned Python and Pygame library.

I noticed that the rendering and main loop is automatically paused when I click and hold on the window menu bar (the bar with the title/icon).

For example, in a snake game, the snake will be moving every frame. When I click and hold (or drag) the window menu, the snake is not moving anymore and the game is "paused". When I release it, it resumes.

Is there a way to let the game NOT pause when I drag the windows menu bar?

like image 701
raybaybay Avatar asked Nov 01 '22 04:11

raybaybay


1 Answers

When you drag the window only the event queue gets stopped. So if your update/draw is not coupled with the event queue, they will not be paused.

from pygame.locals import *
import pygame
import sys

import time;
import random;

pygame.init()
DISPLAYSURF = pygame.display.set_mode((530, 212))

while True:
    t = random.random();
    t *= 255;
    for event in pygame.event.get():        
        if event.type == QUIT:
            pygame.quit()
        print event;

    DISPLAYSURF.fill((int(t) % 255, int(t) % 255, int(t) % 255));
    pygame.display.update()
like image 181
n2omatt Avatar answered Nov 15 '22 04:11

n2omatt