sdl2.ext.time - track and control game time and framerate.

Track and control game time and framerate.

Note

This is a MODIFIED, pure Python implementation of time-related functions from PyGameSDL2’s time, in Cython, released under zlib license.

PygameSDL2 Notice / zlib License:

--------------------------------------------------------------------------
Original work:
  Copyright 2014 Tom Rothamel <tom@rothamel.us>
  Copyright 2014 Patrick Dawson <pat@dw.is>
Modified work:
  Copyright 2017 Lucas Siqueira <lucas.morais.siqueira@gmail.com>

This software is provided 'as-is', without any express or implied
warranty.  In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
   claim that you wrote the original software. If you use this software
   in a product, an acknowledgment in the product documentation would be
   appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not
   be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
   distribution.
--------------------------------------------------------------------------
class sdl2.ext.time.Clock

Bases: object

Clock is used track and control the framerate of a game.

The clock can be used to limit the framerate of a game, as well as track the time used per frame.

Usage:
clock = time.Clock()
__init__()

Initialization.

get_fps()

Compute the clock framerate.

Compute your game’s framerate (in frames per second). It is computed by averaging the last ten calls to Clock.tick().

Usage:
get_fps()
Returns:float
get_rawtime()

Actual time used in the previous tick.

Similar to Clock.get_time(), but this does not include any time used while clock.tick() was delaying to limit the framerate.

Usage:
clock.get_rawtime()
Returns:int (milliseconds)
get_time()

Time used in the previous tick.

Returns the parameter passed to the last call to Clock.tick().

Usage:
clock.get_time()
Returns:int (milliseconds)
tick(framerate=0)

Update the Clock.

This method should be called once per frame. 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.

Usage:
tick(framerate=0)
Returns:float (milliseconds)
sdl2.ext.time.wait(milliseconds)

Pause the program for an amount of time.

Will pause for a given number of milliseconds. This function sleeps the process to share the processor with other programs. A program that waits for even a few milliseconds will consume very little processor time.

Usage:
wait(milliseconds)
Returns:int (the actual number of milliseconds used)
sdl2.ext.time.get_time()

Get the current time from SDL clock.

sdl2.ext.time.get_delta(t0)

Get the time elapsed since the passed time.