简体   繁体   中英

Pygame built-in automatic pause?

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?

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()

This one is pretty easy, its seems you forgot to add a event callback. state 1 while (sate != 0): for event in pygame.event.get():

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM