I tried to subscribe inputs for my orbit camera but browser show this warning:
EventHandler: subscribing to an event ((deltaX, deltaY) => { console.log(“Drag Event:”, deltaX, deltaY); this.applyRotate(deltaX, deltaY); }) with missing arguments
var MouseInput = pc.createScript('mouseInput');
MouseInput.instance = null;
MouseInput.getInstance = function(app) {
if (!MouseInput.instance) {
var entity = new pc.Entity('MouseInputEntity');
app.root.addChild(entity);
MouseInput.instance = entity.addComponent('script').create('mouseInput');
}
return MouseInput.instance;
};
MouseInput.prototype.initialize = function() {
// Initialize custom events
this.onDrag = new pc.EventHandler();
this.onPinch = new pc.EventHandler();
MouseInput.instance = this;
// Bind mouse events
this.app.mouse.on(pc.EVENT_MOUSEMOVE, this.onMouseMove, this);
this.app.mouse.on(pc.EVENT_MOUSEWHEEL, this.onMouseWheel, this);
};
MouseInput.prototype.onMouseMove = function(event) {
// Check if the left mouse button is pressed
if (!event.buttons[pc.MOUSEBUTTON_LEFT]) return;
// Trigger OnDrag event with delta movement
this.onDrag.fire(event.dx, event.dy);
};
MouseInput.prototype.onMouseWheel = function(event) {
// Trigger OnPinch event with wheel delta
this.onPinch.fire(event.wheel);
};
MouseInput.prototype.destroy = function() {
if (MouseInput.instance === this) {
MouseInput.instance = null;
}
// Unbind mouse events
this.app.mouse.off(pc.EVENT_MOUSEMOVE, this.onMouseMove, this);
this.app.mouse.off(pc.EVENT_MOUSEWHEEL, this.onMouseWheel, this);
};
Event Subscribe:
CameraOrbit.prototype.inputSetup = function () {
// Mouse Input
var mouseInput = MouseInput.getInstance(this.app);
mouseInput.onDrag.on((deltaX, deltaY) => { console.log("Drag Event:", deltaX, deltaY); this.applyRotate(deltaX, deltaY); });
mouseInput.onPinch.on((deltaDistance) => { this.applyDistance(deltaDistance); });
// Touch Input
var touchInput = TouchInput.getInstance(this.app);
touchInput.onDrag.on((deltaX, deltaY) => { this.applyRotate(deltaX, deltaY); });
touchInput.onPinch.on((deltaDistance) => { this.applyDistance(deltaDistance); });
};