cocos.fps module

Support to collect and display fps stats.

The default fps support calculates very simple stats and provides a view for director to display. This is enough most of the time, if more functionality is desired then

  • Define your own FpsStatsABC subclass with the desired behavior.

  • Define a callable that returns an instance of your custom subclass.

  • Assign the callable to director.fps_display_provider.

  • If other stats handler is running, do director.show_FPS=False or ctrl + X to cleanly terminate it.

  • re-enable stats collection with ctrl + X (interactive) or by director.show_FPS=True (programatically).

  • your subclass instance will be called as described in :class:FpsStatsABC.

class FpsDisplay(fn_time)

Bases: cocos.fps.FpsStatsABC

Calculates fps and min fps, maintains a Label view for director to display them.

Parameters

fn_time – function Provides time in seconds to calculate deltas Assumes fn_time minimum dt < dt between frames, usually time.perf_counter (needs python 3.3+)

min fps capped at 5000, it can also be 5000 if no frame has rendered in the refresh interval

Don’t use time.clock as fn_time in platforms other than windows: it will flow slower than wall time.

complete_refresh(t)

re-initializes data for the next stats time interval.

draw()

Draws the fps view.

init()

Creates the label used to display fps info.

terminate()

Nothing needed, so nothing done.

tick()

Called after the active scene was drawn. Updates stats.

template = 'fps {0:4d} minfps {1:4d}'
class FpsDisplayDeprecatedPygletOldStyle

Bases: cocos.fps.FpsStatsABC

Calculates fps and maintains a view (not recommended for new code)

Delegates to (deprecated) pyglet.clock.ClockDisplay.

Measurements are comparable to the ones obtained in cocos <= 0.6.3

draw()

Opportunity to draw stats on top of the active scene, called after tick.

Normally it draws itself in the window, but can be implemented with a ‘pass’ if the object is designed to gather stats and not display them.

init()

Called once before any other method; performs initialization.

The window and the associated OpenGL context is guaranteed to exist at the time of calling.

Usually used to create the Label to display fps stats.

terminate()

last call to this object, opportunity to cleanup / store data.

tick()

Called each time the active scene has been draw; updates the stats

If there is a view its data can be eventually updated.

class FpsDisplaySimple(fn_time)

Bases: cocos.fps.FpsStatsABC

Calculates fps, creates and maintains a Label view for director to display it.

Parameters

fn_time (function) – provide time in seconds to calculate deltas; usually time.time is used

Don’t use time.clock as fn_time in platforms other than windows: it will flow slower than wall time.

complete_refresh(t)

re-initializes data for the next stats time interval

draw()

Draws the fps view

init()

Creates the label used to display fps

terminate()

Nothing needed, so nothing done

tick()

Called after the active scene was drawn. Updates stats

template = 'fps {0:4d}'
class FpsStatsABC

Bases: object

Interface to collect fps stats, optionally maintains a view

Methods are called by director at appropriate times.

abstract draw()

Opportunity to draw stats on top of the active scene, called after tick.

Normally it draws itself in the window, but can be implemented with a ‘pass’ if the object is designed to gather stats and not display them.

abstract init()

Called once before any other method; performs initialization.

The window and the associated OpenGL context is guaranteed to exist at the time of calling.

Usually used to create the Label to display fps stats.

abstract terminate()

last call to this object, opportunity to cleanup / store data.

abstract tick()

Called each time the active scene has been draw; updates the stats

If there is a view its data can be eventually updated.

class InfoLabel(template, font_name=None, font_size=36, color=128, 128, 128, 128)

Bases: object

Used to draw one liners on top of the scene drawing

draw()
update_info(*args)
get_default_fpsdisplay()

returns an FpsStatsABC instance used to collect and display fps information.