Python Forum
pygame, sprites, and rects
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pygame, sprites, and rects
#11
This program records events when they occur, and then processes them one at a time, like happens when you use poll.
import pygame
import time


pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((200, 200))
events = []

max_delay = 0
event = []
while True:
    current_time = time.time()
    for event in pygame.event.get():
        events.append((event, current_time))

    if events:
        event, event_time = events.pop(0)
        delay = current_time - event_time
        if delay > max_delay:
            max_delay = delay
            print(delay)
        if event.type == pygame.QUIT:
            break
    clock.tick(60)

pygame.quit()
There are a lot of events that all happen as soon as the program starts running. You can see that each is delayed 1/60th of a second longer than the previous event.
Output:
0.0009989738464355469 0.0180361270904541 0.034859418869018555 0.051959991455078125 0.06901097297668457 0.08533716201782227 0.10115480422973633
Wiggle the mouse around inside the window while mashing the mouse buttons and the delays can get bigger.
Output:
0.3165292739868164 0.3176705837249756 0.33345532417297363
1/3 of a second is forever in some games. In others it doesn't matter at all.
Reply


Messages In This Thread
pygame, sprites, and rects - by menator01 - Oct-25-2023, 04:25 AM
RE: pygame, sprites, and rects - by deanhystad - Oct-25-2023, 01:34 PM
RE: pygame, sprites, and rects - by Windspar - Oct-25-2023, 08:09 PM
RE: pygame, sprites, and rects - by menator01 - Oct-25-2023, 09:59 PM
RE: pygame, sprites, and rects - by deanhystad - Oct-26-2023, 10:00 PM
RE: pygame, sprites, and rects - by menator01 - Oct-27-2023, 01:40 AM
RE: pygame, sprites, and rects - by menator01 - Oct-28-2023, 03:59 PM
RE: pygame, sprites, and rects - by Windspar - Oct-31-2023, 06:53 AM
RE: pygame, sprites, and rects - by menator01 - Oct-31-2023, 10:45 AM
RE: pygame, sprites, and rects - by Windspar - Nov-01-2023, 03:23 AM
RE: pygame, sprites, and rects - by deanhystad - Nov-01-2023, 09:36 PM
RE: pygame, sprites, and rects - by Windspar - Nov-02-2023, 12:52 AM
RE: pygame, sprites, and rects - by Benixon - Dec-07-2023, 02:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Sprites just randomly appear and dissapear in my pygame.sprite.GoupeSingle trueShadoWrr 2 2,070 Feb-13-2023, 09:34 AM
Last Post: Vadanane
  [PyGame] I found a way to generate sprites without .blit. Is it effecient? xBlackHeartx 19 8,729 Dec-07-2019, 01:06 PM
Last Post: metulburr
  [pygame] transparent rects SheeppOSU 2 2,349 Jun-10-2019, 03:41 PM
Last Post: SheeppOSU
  [PyGame] Having 4 players(Sprites) all being able to jump ElijahCastle 5 4,106 May-07-2019, 05:04 PM
Last Post: SheeppOSU
  Sprites and Actor error ajlconsulting 6 9,501 Jan-30-2019, 12:50 AM
Last Post: metulburr
  draw not showing all sprites ethanstrominger 0 2,654 Jan-25-2019, 10:10 PM
Last Post: ethanstrominger
  [PyGame] move randomly sprites reutB 4 8,334 Mar-29-2017, 01:12 PM
Last Post: metulburr
  How can I get rid of the line following the sprites? Houston11 1 3,790 Jan-06-2017, 10:14 PM
Last Post: Mekire

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020