28 lines
467 B
JavaScript
28 lines
467 B
JavaScript
|
|
||
|
class Cursor {
|
||
|
constructor(){
|
||
|
this.x = 0
|
||
|
this.y = 0
|
||
|
this.xold = 0
|
||
|
this.yold = 0
|
||
|
}
|
||
|
|
||
|
}
|
||
|
export var cursor = new Cursor();
|
||
|
|
||
|
hud.addEventListener('mousemove', e => {
|
||
|
mouseMoved(e)
|
||
|
});
|
||
|
|
||
|
function mouseMoved(event) {
|
||
|
const x = Math.floor(event.offsetX/main.game.tileSize)
|
||
|
const y = Math.floor(event.offsetY/main.game.tileSize)
|
||
|
if (cursor.xold != x || cursor.yold != y) {
|
||
|
cursor.x = x
|
||
|
cursor.y = y
|
||
|
renderHud(x, y)
|
||
|
cursor.xold = x
|
||
|
cursor.yold = y
|
||
|
}
|
||
|
}
|