To animate a Live2D model, it must be updated every frame using model.update(deltaTime). You can choose between automatic or manual updates.
Automatic Updates (Default)
By default, models attempt to use PIXI.Ticker.shared. To enable this, you must ensure PIXI is available in the global scope:
import * as PIXI from 'pixi.js';
window.PIXI = PIXI;
If you are using a modular setup, you must manually register the Ticker:
import { Application } from '@pixi/app';
import { Ticker, TickerPlugin } from '@pixi/ticker';
Application.registerPlugin(TickerPlugin);
Live2DModel.registerTicker(Ticker);
Manual Updates
To control the update loop yourself, set autoUpdate: false in the creation options and call .update() in your own loop.
Using Ticker
const model = await Live2DModel.from('shizuku.model.json', { autoUpdate: false });
const ticker = new Ticker();
ticker.add(() => model.update(ticker.elapsedMS));
Using requestAnimationFrame
const model = await Live2DModel.from('shizuku.model.json', { autoUpdate: false });
let then = performance.now();
function tick(now) {
model.update(now - then);
then = now;
requestAnimationFrame(tick);
}
requestAnimationFrame(tick);
const model = await Live2DModel.from('shizuku.model.json', { autoUpdate: false });
const ticker = new Ticker();
ticker.add(() => model.update(ticker.elapsedMS));