Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Fix zooming too fast with trackpad #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion SupEngine/src/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ export default class Input extends EventEmitter {

private onMouseWheel = (event: MouseWheelEvent) => {
event.preventDefault();
this.newScrollDelta = (event.wheelDelta > 0 || event.detail < 0) ? 1 : -1;
this.newScrollDelta = 0;
if ((event.wheelDelta || event.detail) !== 0) {
this.newScrollDelta = (event.wheelDelta > 0 || event.detail < 0) ? 1 : -1;
}
return false;
};

Expand Down
5 changes: 4 additions & 1 deletion SupEngine/src/components/Camera2DControls.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as THREE from "three";
import { throttle } from "lodash";
import ActorComponent from "../ActorComponent";
import Actor from "../Actor";
import Camera from "./Camera";
Expand Down Expand Up @@ -47,6 +48,8 @@ export default class Camera2DControls extends ActorComponent {
if (this.zoomCallback != null) this.zoomCallback();
}

throttledChangeOrthographicScale = throttle(this.changeOrthographicScale, 75, { trailing: false });

update() {
let input = this.actor.gameInstance.input;
let keys = (<any>window).KeyEvent;
Expand Down Expand Up @@ -84,7 +87,7 @@ export default class Camera2DControls extends ActorComponent {
}

if (newOrthographicScale != null && newOrthographicScale !== this.camera.orthographicScale) {
this.changeOrthographicScale(newOrthographicScale, mousePosition.x, mousePosition.y);
this.throttledChangeOrthographicScale(newOrthographicScale, mousePosition.x, mousePosition.y);
}
}
}
Expand Down