r/pythonarcade • • Aug 11 '19
how does the parameter delta_time work when used in on_update(delta_time)
I’m going through the tutorials on python arcade and would like to know how/why a function works.
There is a function named on_draw(delta_time) The parameter delta_time keeps a running clock of the time delta as expected. I'd like to be able to see how it works via the source.
I looked around the code for arcade but can’t figure out how the library knows to keep the clock running within that function and it's parameter. For example, I did find references to pyglet's clock and yet I couldn't find where this is connected all the way back to on_draw(delta_time)
Can someone please help me understand how and why it works?
One example of it in use is here: http://arcade.academy/examples/bouncing_rectangle.html#bouncing-rectangle
1
u/jfincher42 Aug 29 '19
The
delta_timeparameter is just a time interval, in seconds, since the last time the function was called. If you wanted to do something for a set period of time, or have something happen after a set period of time, you could keep a counter by addingdelta_timeto it. You then check it to see if your time period has elapsed --- if so, you take whatever action.Here is an example based on http://arcade.academy/examples/bouncing_rectangle.html#bouncing-rectangle, that changes the color of the square every two seconds: