Constructor
new Mortar(cbopt, fpsopt)
Creates a new instance of the Mortar object.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
cb |
function
|
<optional> |
The function to be called at the given frame rate. It receives two arguments: the time since it started, and the elapsed time since the previous frame (or delta time). | |
fps |
Number
|
<optional> |
60 | The integer number of times to call the callback function per second (frames per second). Number must be an integer. |
Example
import { Mixer, Spice, Mortar } from 'paprika-tween';
const spice = new Spice({
duration: 5000,
from: { scale: 1 },
to: { scale: 2.5 },
render: (props, interpolation) => { ... }
});
const mixer = new Mixer();
mixer.add(spice)
.start();
const mortar = new Mortar((time) => mixer.frame(time));
mortar.start();
Classes
Members
running :Boolean
Returns whether the instance is running or not.
Type:
-
Boolean
time :DOMHighResTimeStamp
Returns the time since the Mortar started.
Type:
-
DOMHighResTimeStamp
Methods
frame()
The
To keep the same speed in your animation, Be sure to use the
frame()
method is called before the browser performs the next repaint, then it calls the callback function.
Mortar will ensure that the callback function is called no more than fps
number of times per second.
To keep the same speed in your animation, Be sure to use the
delta
argument to calculate how much the
animation will progress in a frame.
Example
import { Mortar } from 'paprika-tween';
function loop(time, delta) {
character.left += character.speed * delta;
}
const mortar = new Mortar(loop, 10);
mortar.start();
start()
Starts the frame-by-frame loop by internally calling to requestAnimationFrame().
The callback function will be called the
fps
number of times per second.
stop()
Stops the frame-by-frame loop and removes the callback function. Further calls to
Mortar#start
will fail.