RedSubmarine
RedSubmarine

Reputation: 197

Pygame delay argument

desired_fps=int(60)
my_delay=1/desired_fps
pygame.time.delay(my_delay)

Error - Delay require one integer argument. When work fine:

pygame.time.delay(60)

Why?

Upvotes: 1

Views: 563

Answers (1)

Rabbid76
Rabbid76

Reputation: 210890

1/desired_fps gives a floating point number. The parameter to pygame.time.delay() has to be integral and its unit is milliseconds.
Since 1 second are 1000 milliseconds, it has to be:

my_delay = int(1000/desired_fps)
pygame.time.delay(my_delay)

respectively

my_delay = 1000 // desired_fps
pygame.time.delay(my_delay)

Note, // is the floor division operator. See Binary arithmetic operations.

Upvotes: 1

Related Questions