drawing loop inside update loop (per second)

151 Views Asked by At

My code simplified:

Clock.tick(UPS): #updates per second
    game.update()
    for frame in range(FPU) #frames per update
        game.draw(frame)

What it should do is that every second there should be a number of updates equal to UPS value. After each update, the number of frames drawn will be equal to FPU. It does mean that FPS is UPS*FPU.

My question is how to set that to be smooth, fluent. Smoothness is the key question of this Question.

I need to have each game.draw() to be equally distant (in time) from each other.

There is Clock = pygame.clock then Clock.tick(UPS*FPU) doesn't work since update happens as many times as draw * FPU.

Should I use clock inside clock? Would that work? (I tried but I'm not sure about the results - whether it would work for all extremes.)

Clock1.tick(UPS):
    game.update()
    Clock2.tick(FPU):
        game.draw(frame)

or maybe just inside clock? would that work?

game.update()
Clock.tick(UPS*FPU)
    game.draw()

There is pygame.Clock of which I'm considering using tick.tick_busy_loop() but that is matter of experimentation - not matter of this Question.

And if you want to you can check out in which project will I be using this. (specifically there).

0

There are 0 best solutions below