From d2277468d09cd07cd173cc261c6192a12982fdeb Mon Sep 17 00:00:00 2001 From: Mathieu Triay Date: Tue, 23 Aug 2016 23:43:19 +0100 Subject: [PATCH] Fix zooming too fast with trackpad --- SupEngine/src/Input.ts | 5 ++++- SupEngine/src/components/Camera2DControls.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/SupEngine/src/Input.ts b/SupEngine/src/Input.ts index 3a2d92c17..2968ed4f4 100644 --- a/SupEngine/src/Input.ts +++ b/SupEngine/src/Input.ts @@ -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; }; diff --git a/SupEngine/src/components/Camera2DControls.ts b/SupEngine/src/components/Camera2DControls.ts index 847b39b55..9874a9cb1 100644 --- a/SupEngine/src/components/Camera2DControls.ts +++ b/SupEngine/src/components/Camera2DControls.ts @@ -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"; @@ -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 = (window).KeyEvent; @@ -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); } } }