mirror of
https://github.com/visgl/luma.gl.git
synced 2025-12-08 17:36:19 +00:00
2.6 KiB
2.6 KiB
AnimationLoopProxy (Expermental)
This class is experimental. Its API may change between minor releases.
Manages an AnimationLoop that runs on a worker thread.
Usage
Create a worker:
// animation-worker.js
import {AnimationLoop, _AnimationLoopProxy as AnimationLoopProxy} from 'luma.gl';
const animationLoop = new AnimationLoop({...});
AnimationLoopProxy.createWorker(animationLoop)(self);
Use a bundler e.g. Webpack to transpile and bundle animation-worker.js into a file e.g. animation-worker.es5.js. You can then use it as this:
import {_AnimationLoopProxy as AnimationLoopProxy} from 'luma.gl';
new AnimationLoopProxy(new Worker('animation-worker.es5.js')).start();
Static Methods
createWorker
AnimationLoopProxy.createWorker(animationLoop);
Returns a function self => {...} that sets up the message handling inside the worker thread when called with a WorkerGlobalScope instance.
Methods
constructor
new AnimationLoopProxy(worker, {
onInitialize,
onFinalize,
useDevicePixels,
autoResizeDrawingBuffer
});
worker- a Worker instance using code created fromAnimationLoopProxy.createWorker.optionsonInitialize(callback) - if supplied, will be called once after firststart()has been called, after page load completes and a context has been created.onFinalize=null(callback) - Called once when animation is stopped. Can be used to delete objects or free any resources created duringonInitialize.autoResizeDrawingBuffer=true- If true, checks the canvas size every frame and updates the drawing buffer size if needed.useDevicePixels- Whether to usewindow.devicePixelRatioas a multiplier, e.g. inautoResizeDrawingBufferetc.
start
Restarts the animation
animationLoopProxy.start(options)
options={}(object) - Options to create the canvas with.options.canvas(string | HTMLCanvasElement) - A string containing theidof an existing HTML element or a DOMElement instance. Ifnullor not provided, a new canvas will be created.
stop
Stops the animation
animationLoopProxy.stop();
setProps
animationLoopProxy.setProps({...props});
autoResizeDrawingBuffer- Update the drawing buffer size to match the canvas size before each call toonRenderFrame()useDevicePixels- Whether to usewindow.devicePixelRatioas a multiplier, e.g. inautoResizeDrawingBufferetc.