S
S
Shroud228lol2020-06-13 20:20:31
Python
Shroud228lol, 2020-06-13 20:20:31

How to deal with time.clock in pygame?

import pygame as pg
pg.init()
clock = pg.time.Clock()
run = True
while run:
    clock.tick(144)

What should be specified in the clock argument? In my code it will be 144 fps, or should I show some kind of delay?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Pokrovsky, 2020-06-13
@Shroud228lol

https://www.pygame.org/docs/ref/time.html#pygame.t...

tick()
update the clock
tick(framerate=0) ->
milliseconds It will compute how many milliseconds have passed since the previous call.
If you pass the optional framerate argument the function will delay to keep the game running slower than the given ticks per second. This can be used to help limit the runtime speed of a game. By calling Clock.tick(40) once per frame, the program will never run at more than 40 frames per second.
Note that this function uses SDL_Delay function which is not accurate on every platform, but does not use much CPU. Use tick_busy_loop if you want an accurate timer, and don't mind chewing CPU.

I
IDzone-x, 2020-06-14
@IDzone-x

Watch this series of Gosha Dudar's course
https://youtu.be/jBpUaD1dpYc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question