mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Terrain brush implemented.
This commit is contained in:
67
tilorswift/js/Mouse.js
Normal file
67
tilorswift/js/Mouse.js
Normal file
@@ -0,0 +1,67 @@
|
||||
export default class Mouse
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
this.isPressedLeft = false;
|
||||
this.isPressedRight = false;
|
||||
this.isPressedMiddle = false;
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
|
||||
this.addListenerMouseUp();
|
||||
this.addListenerMouseDown();
|
||||
this.addListenerMouseMove()
|
||||
}
|
||||
|
||||
addListenerMouseUp()
|
||||
{
|
||||
window.addEventListener(
|
||||
'mouseup',
|
||||
(event) => {
|
||||
switch (event.button) {
|
||||
case 0:
|
||||
this.isPressedLeft = false;
|
||||
break;
|
||||
case 1:
|
||||
this.isPressedMiddle = false;
|
||||
break;
|
||||
case 2:
|
||||
this.isPressedRight = false;
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
addListenerMouseMove()
|
||||
{
|
||||
window.addEventListener(
|
||||
'mousemove',
|
||||
(event) => {
|
||||
this.x = event.clientX;
|
||||
this.y = event.clientY;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
addListenerMouseDown()
|
||||
{
|
||||
window.addEventListener(
|
||||
'mousedown',
|
||||
(event) => {
|
||||
switch (event.button) {
|
||||
case 0:
|
||||
this.isPressedLeft = true;
|
||||
break;
|
||||
case 1:
|
||||
this.isPressedMiddle = true;
|
||||
break;
|
||||
case 2:
|
||||
this.isPressedRight = true;
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user