@slackmoehrle @jare @mmyduckx I am getting an error:
Error occurs in an event listener: mouse-move
_emitEvent @ input.ts:298
_dispatchOrPushEvent @ input.ts:385
(anonymous) @ input.ts:324
emit @ callbacks-invoker.ts:346
(anonymous) @ mouse-input.ts:171
input.ts:299 TypeError: Cannot read properties of null (reading ‘cameraPriority’)
at PointerEventDispatcher._sortPointerEventProcessorList (pointer-event-dispatcher.ts:189:69)
at PointerEventDispatcher.dispatchEventMouse (pointer-event-dispatcher.ts:97:14)
at PointerEventDispatcher.dispatchEvent (pointer-event-dispatcher.ts:68:25)
at Input._emitEvent (input.ts:294:33)
at Input._dispatchOrPushEvent (input.ts:385:18)
at input.ts:324:22
at Eventified.emit (callbacks-invoker.ts:346:25)
at HTMLCanvasElement. (mouse-input.ts:171:31)
Steps:
Added sphere.
Attached the script to rotate on sphere.
import { _decorator, Component, EventMouse, EventTouch, Node, Quat } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('RotateOnDrag')
export class RotateOnDrag extends Component {
private _rotating: boolean = false;
private _lastX: number = 0;
start() {
this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this);
this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
this.node.on(Node.EventType.MOUSE_DOWN, this.onMouseDown, this);
this.node.on(Node.EventType.MOUSE_MOVE, this.onMouseMove, this);
this.node.on(Node.EventType.MOUSE_UP, this.onMouseUp, this);
}
// Touch event handlers
onTouchStart(event: EventTouch) {
this._startRotate(event.getLocationX());
}
onTouchMove(event: EventTouch) {
this._rotate(event.getLocationX());
}
onTouchEnd(event: EventTouch) {
this._stopRotate();
}
// Mouse event handlers
onMouseDown(event: EventMouse) {
this._startRotate(event.getLocationX());
}
onMouseMove(event: EventMouse) {
this._rotate(event.getLocationX());
}
onMouseUp(event: EventMouse) {
this._stopRotate();
}
private _startRotate(x: number) {
this._rotating = true;
this._lastX = x;
}
private _rotate(x: number) {
if (this._rotating) {
let deltaX = x - this._lastX;
let deltaRotationQuaternion = new Quat();
Quat.fromEuler(deltaRotationQuaternion, 0, deltaX * 0.5, 0);
this.node.rotation = Quat.multiply(new Quat(), this.node.rotation, deltaRotationQuaternion);
this._lastX = x;
}
}
private _stopRotate() {
this._rotating = false;
}
}
play on browser.