UNPKG

valaxy-addon-live2d

Version:

<a href="https://www.npmjs.com/package/valaxy-addon-live2d" rel="nofollow"><img src="https://img.shields.io/npm/v/valaxy-addon-live2d?color=0078E7" alt="NPM version"></a>

22 lines (21 loc) 626 B
export function draggable(_model) { const model = _model; model.on('pointerdown', onPointerDown); model.on('pointermove', onPointerMove); model.on('pointerup', onPointerUp); model.on('pointerupoutside', onPointerUp); } function onPointerDown(e) { this.dragging = true; this._pointerX = e.data.global.x - this.x; this._pointerY = e.data.global.y - this.y; } function onPointerMove(e) { if (this.dragging) { this.position.x = e.data.global.x - this._pointerX; this.position.y = e.data.global.y - this._pointerY; } } function onPointerUp(_e) { this.dragging = false; }