mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
added mouse wheel for zooming
This commit is contained in:
parent
59978429c7
commit
93857ced2d
2 changed files with 26 additions and 1 deletions
|
|
@ -27,10 +27,30 @@ define(['Lib/Vendor/Three', 'Game/Config/Settings'], function (Three, Settings)
|
|||
);
|
||||
}
|
||||
|
||||
this.camera.position.z = 481;
|
||||
this.camera.position.z = 481; // 481
|
||||
this.setPosition(Settings.STAGE_WIDTH / 2, -Settings.STAGE_HEIGHT / 2);
|
||||
|
||||
this.initWheel();
|
||||
}
|
||||
|
||||
CameraController.prototype.initWheel = function() {
|
||||
var callback = this.handleWheel.bind(this);
|
||||
if(window.addEventListener)
|
||||
window.addEventListener("DOMMouseScroll", callback, false);
|
||||
else
|
||||
window.onmousewheel = document.onmousewheel = callback;
|
||||
};
|
||||
|
||||
CameraController.prototype.handleWheel = function(event) {
|
||||
var delta = 0;
|
||||
if(!event) event = window.event; // IE
|
||||
if(event.wheelDelta) delta = event.wheelDelta/120;
|
||||
else if(event.detail) delta = -event.detail/3;
|
||||
if(delta) this.camera.position.z += delta * 10;
|
||||
if(event.preventDefault) event.preventDefault();
|
||||
event.returnValue = false;
|
||||
};
|
||||
|
||||
CameraController.prototype.getCamera = function () {
|
||||
return this.camera;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue