@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
36 lines (28 loc) • 855 B
JavaScript
import {noop} from "../../../../core/function/noop.js";
export class DragHandler {
/**
*
* @param {function} [dragStart=noop]
* @param {(position:Vector2,delta:Vector2)=>*} [drag=noop]
* @param {function} [dragEnd=noop]
*/
constructor({dragStart = noop, drag = noop, dragEnd = noop}) {
this.dragStartCallback = dragStart;
this.dragCallback = drag;
this.dragEndCallback = dragEnd;
this.active = false;
}
start(position) {
this.active = true;
this.dragStartCallback(position);
}
drag(position, delta) {
if (!this.active) return;
this.dragCallback(position, delta);
}
end(position) {
if (!this.active) return;
this.active = false;
this.dragEndCallback(position);
}
}