fix weird touch behavior

This commit is contained in:
biglyderv 2025-05-20 20:41:08 -04:00
parent 2e39d119a4
commit 611a2da315
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
2 changed files with 19 additions and 16 deletions

View file

@ -56,6 +56,7 @@ div#header-title {
#header-links a {
margin-top: 0;
text-decoration: none;
}
#header {

View file

@ -27,18 +27,18 @@ function Canvas(width, height, upscale) {
let that = this;
function clicker(e) {
that.clicked = true;
that.pageX = e.touches[0].pageX;
that.pageY = e.touches[0].pageY;
}
this.elem.addEventListener('mousedown', function (e) {
that.clicked = true;
});
this.elem.addEventListener('touchstart', function (e) {
that.clicked = true;
});
this.elem.addEventListener('touchstart', clicker);
this.elem.addEventListener('touchmove', function (e) {
that.pageX = e.touches[0].pageX;
that.pageY = e.touches[0].pageY;
})
this.elem.addEventListener('touchmove', clicker)
this.elem.addEventListener('mousemove', function (e) {
that.pageX = e.pageX;
@ -57,18 +57,18 @@ function Canvas(width, height, upscale) {
e.preventDefault();
})
this.elem.addEventListener('mouseup', function (e) {
this.elem.addEventListener('touchend', function (e) {
that.clicked = false;
that.firstX = this.pageX;
that.firstY = this.pageY;
});
this.elem.addEventListener('touchend', function (e) {
this.elem.addEventListener('mouseup', function (e) {
that.clicked = false;
that.firstX = this.pageX;
that.firstY = this.pageY;
that.firstX = e.touches[0].pageY;
that.firstY = e.touches[0].pageY;
});
@ -163,12 +163,14 @@ Canvas.prototype.render = function () {
this.ctx.strokeStyle = 'rgb(255,255,255)';
this.ctx.lineWidth = 2;
let theX = Math.floor(x / this.upscale);
let theY = Math.floor(y / this.upscale);
if (this.isMouseOver || this.forceShowTilePlacement)
this.ctx.strokeRect(x / this.upscale, y / this.upscale, this.radius * 2 + 2, this.radius * 2 + 2);
let theX = Math.floor(x / this.upscale + this.radius + 1);
let theY = Math.floor(y / this.upscale + this.radius + 1);
this.ctx.strokeRect(theX, theY, this.radius * 2 + 2, this.radius * 2 + 2);
theX += this.radius + 1;
theY += this.radius + 1;
let blok = mainTiles.tiles[this.getBlock(theX, theY)];