-
Notifications
You must be signed in to change notification settings - Fork 48
Methods
FPSMeter has a handful of very useful methods. You can call them directly on a new FPSMeter object:
var meter = new FPSMeter(anchor, options);
meter.hide();
All methods return the current FPSMeter object, unless specified otherwise. This means that you can chain method calls if you want:
var meter = new FPSMeter(anchor, options).hide();
meter.showDuration().show();
meter.tick();
Marks the end of each frame. This is the method that measures everything.
Returns: this method doesn't return anything.
Example:
// Function that renders one frame
function render() {
// ... rendering happens here ...
meter.tick();
}
meter.tickStart();
Marks the beginning of each frame. .tick()
than uses this time to measure the rendering duration of each frame. This method is optional, and if omitted, .tick()
will measure the duration between frames instead.
Returns: this method doesn't return anything.
Example:
// Function that renders one frame
function render() {
meter.tickStart();
// ... rendering happens here ...
meter.tick();
}
meter.showFps();
Changes the meter to display FPS.
meter.showDuration();
Changes the meter to display duration between frames, or frame rendering duration when using .tickStart()
method.
meter.toggle();
Toggles between showFps
amd showDuration
.
meter.pause();
Pauses the meter rendering. FPSMeter still continues to measure everything, just the meter element rendering is paused.
meter.resume();
Resumes the paused rendering.
meter.hide();
Pauses the rendering, and hides the FPSMeter element.
meter.show();
Shows the FPSMeter element, and resumes the rendering.
meter.set( name, value );
Updates an option value, and when needed, repositions or reloads the meter element.
- name - name of the option to be updated
- value - new option value
All options from Options documentation can be updated dynamically. Example:
// Changes theme to 'colorful'
meter.set('theme', 'colorful');
// Hides the graph
meter.set('graph', 0);
meter.destroy();
Pauses rendering, unbinds events, removes the element from DOM, and stops listening to ticks.
Returns: This method doesn't return anything, because fuck you, y u destroying me?