0

i can't add seconds to my program without it slowing the whole program to 1 frame per second so the screensaver moving "welcome" thing will slow down as well so i don't want that but still want the timer thingy. this is the code:

import random
import pygame
pygame.init()
screen = pygame.display.set_mode((1920,1080))
bg = pygame.image.load('C:/Users/zaydz/Desktop/coding/python/python programs/images/backrooms.jpg')
mover = pygame.image.load('C:/Users/zaydz/Desktop/coding/python/python programs/images/welcome.png')
seconds = 0
minutes = 0
hours = 0
mx = random.randrange(400,1520)
my = random.randrange(200,880)
sx = 3
sy = 2
current_time = 0
clock = pygame.time.Clock()
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    current_time = pygame.time.get_ticks()
    if current_time > 1000:
        pygame.time.wait(1000)
        seconds += 1
    if seconds == 60:
        minutes += 1
        seconds = 0 
    if minutes == 60:
        hours += 1
        minutes = 0
    if hours == 24:
        seconds = 0
        minutes = 0
        hours = 0
    mx += sx
    my += sy
    if mx <= 0 or mx >= 1520:
        sx *= -1
    if my <=0 or my >= 880:
        sy *= -1
    tume = pygame.font.Font("C:/Users/zaydz/Desktop/coding/python/python programs/fonts/Sitka.ttc",50)
    tumo = tume.render(f"hour : {hours}  minute : {minutes}  second : {seconds}",False,(237, 205, 187))
    screen.blit(bg,(0,0))
    screen.blit(mover,(mx,my))
    screen.blit(tumo,(0,0))
    pygame.display.update()
    clock.tick(50)
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • Please correct the formatting to properly display as code. – StephanT Dec 07 '22 at 12:33
  • 1
    after checking `if current_time > 1000` you do `pygame.time.wait(1000)` which waits 1 second and thus reduces your fps to 1. Why are you doing the `time.wait(1000)`? – Sembei Norimaki Dec 07 '22 at 12:36
  • i do this to make the seconds add 1 per second if i don't do that then the seconds add very quickly – mr.nokia ringtone Dec 07 '22 at 12:36
  • replace the wait with a running sum of `clock.tick()` and add a second every time the running sum hits 1 (and then subtract 1) – Nullman Dec 07 '22 at 12:39
  • you are basically freezing your program 1 second every time. Take a look here on how to count time in pygame https://stackoverflow.com/questions/45520104/counting-time-in-pygame – Sembei Norimaki Dec 07 '22 at 12:39

0 Answers0