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
#12
That at best. There also so many other factors. Like when computer running other programs. When code has to do a lot of calculating. No program can guarantee fps. Pygame clock will idle fps down to 60, but it can go lower. Running code of different hardware will have different result.
99 percent of computer problems exists between chair and keyboard.
Reply
#13
I worked it out but went another route because I couldn't figure out how to make the bar decrease and change colors as it got lower.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Sprites just randomly appear and dissapear in my pygame.sprite.GoupeSingle trueShadoWrr 2 2,002 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,496 Dec-07-2019, 01:06 PM
Last Post: metulburr
  [pygame] transparent rects SheeppOSU 2 2,303 Jun-10-2019, 03:41 PM
Last Post: SheeppOSU
  [PyGame] Having 4 players(Sprites) all being able to jump ElijahCastle 5 4,030 May-07-2019, 05:04 PM
Last Post: SheeppOSU
  Sprites and Actor error ajlconsulting 6 9,381 Jan-30-2019, 12:50 AM
Last Post: metulburr
  draw not showing all sprites ethanstrominger 0 2,600 Jan-25-2019, 10:10 PM
Last Post: ethanstrominger
  [PyGame] move randomly sprites reutB 4 8,257 Mar-29-2017, 01:12 PM
Last Post: metulburr
  How can I get rid of the line following the sprites? Houston11 1 3,757 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