fix(physarum): paint only while the pointer is pressed
Ignore pointer moves after release.
This commit is contained in:
1 parent
0013dc175a
commit
26601bef46
1 file changed
+6
-6
@@ -70,7 +70,8 @@ export class PhysarumComponent implements OnDestroy {
|
|||||||
private canvas: HTMLCanvasElement | null = null;
|
private canvas: HTMLCanvasElement | null = null;
|
||||||
private pointerAttached = false;
|
private pointerAttached = false;
|
||||||
private agentCountInitialized = false;
|
private agentCountInitialized = false;
|
||||||
private readonly pointerLeaveHandler = () => { this.food.active = false; };
|
private pressed = false;
|
||||||
|
private readonly pointerLeaveHandler = () => { this.pressed = false; this.food.active = false; };
|
||||||
private readonly fpsCounter = new FpsCounter();
|
private readonly fpsCounter = new FpsCounter();
|
||||||
|
|
||||||
readonly minAgents = MIN_AGENTS;
|
readonly minAgents = MIN_AGENTS;
|
||||||
@@ -231,17 +232,16 @@ export class PhysarumComponent implements OnDestroy {
|
|||||||
|
|
||||||
scene.onPointerObservable.add((info) => {
|
scene.onPointerObservable.add((info) => {
|
||||||
if (info.type === PointerEventTypes.POINTERUP) {
|
if (info.type === PointerEventTypes.POINTERUP) {
|
||||||
|
this.pressed = false;
|
||||||
this.food.active = false;
|
this.food.active = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (info.type !== PointerEventTypes.POINTERDOWN && info.type !== PointerEventTypes.POINTERMOVE) {
|
if (info.type === PointerEventTypes.POINTERDOWN) {
|
||||||
|
this.pressed = true;
|
||||||
|
} else if (info.type !== PointerEventTypes.POINTERMOVE || !this.pressed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const event = info.event as PointerEvent;
|
const event = info.event as PointerEvent;
|
||||||
if (!(event.buttons & 1) && event.pointerType !== 'touch') {
|
|
||||||
this.food.active = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const target = event.target as HTMLElement;
|
const target = event.target as HTMLElement;
|
||||||
const cell = pointerToCell(event.offsetX, event.offsetY, target.clientWidth, target.clientHeight, this.mapSize(), this.mapSize());
|
const cell = pointerToCell(event.offsetX, event.offsetY, target.clientWidth, target.clientHeight, this.mapSize(), this.mapSize());
|
||||||
this.food.x = cell.x;
|
this.food.x = cell.x;
|
||||||
|
|||||||
Reference in new issue
Block a user