fix weird touch behavior
This commit is contained in:
parent
2e39d119a4
commit
611a2da315
2 changed files with 19 additions and 16 deletions
|
@ -56,6 +56,7 @@ div#header-title {
|
||||||
|
|
||||||
#header-links a {
|
#header-links a {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
#header {
|
#header {
|
||||||
|
|
34
js/core.js
34
js/core.js
|
@ -27,18 +27,18 @@ function Canvas(width, height, upscale) {
|
||||||
|
|
||||||
let that = this;
|
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) {
|
this.elem.addEventListener('mousedown', function (e) {
|
||||||
that.clicked = true;
|
that.clicked = true;
|
||||||
});
|
});
|
||||||
this.elem.addEventListener('touchstart', function (e) {
|
this.elem.addEventListener('touchstart', clicker);
|
||||||
that.clicked = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
this.elem.addEventListener('touchmove', clicker)
|
||||||
this.elem.addEventListener('touchmove', function (e) {
|
|
||||||
that.pageX = e.touches[0].pageX;
|
|
||||||
that.pageY = e.touches[0].pageY;
|
|
||||||
})
|
|
||||||
|
|
||||||
this.elem.addEventListener('mousemove', function (e) {
|
this.elem.addEventListener('mousemove', function (e) {
|
||||||
that.pageX = e.pageX;
|
that.pageX = e.pageX;
|
||||||
|
@ -57,18 +57,18 @@ function Canvas(width, height, upscale) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
})
|
})
|
||||||
|
|
||||||
this.elem.addEventListener('mouseup', function (e) {
|
this.elem.addEventListener('touchend', function (e) {
|
||||||
that.clicked = false;
|
that.clicked = false;
|
||||||
|
|
||||||
that.firstX = this.pageX;
|
that.firstX = this.pageX;
|
||||||
that.firstY = this.pageY;
|
that.firstY = this.pageY;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.elem.addEventListener('touchend', function (e) {
|
this.elem.addEventListener('mouseup', function (e) {
|
||||||
that.clicked = false;
|
that.clicked = false;
|
||||||
|
|
||||||
that.firstX = this.pageX;
|
that.firstX = e.touches[0].pageY;
|
||||||
that.firstY = this.pageY;
|
that.firstY = e.touches[0].pageY;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,12 +163,14 @@ Canvas.prototype.render = function () {
|
||||||
|
|
||||||
this.ctx.strokeStyle = 'rgb(255,255,255)';
|
this.ctx.strokeStyle = 'rgb(255,255,255)';
|
||||||
this.ctx.lineWidth = 2;
|
this.ctx.lineWidth = 2;
|
||||||
|
|
||||||
|
let theX = Math.floor(x / this.upscale);
|
||||||
|
let theY = Math.floor(y / this.upscale);
|
||||||
if (this.isMouseOver || this.forceShowTilePlacement)
|
if (this.isMouseOver || this.forceShowTilePlacement)
|
||||||
this.ctx.strokeRect(x / this.upscale, y / this.upscale, this.radius * 2 + 2, this.radius * 2 + 2);
|
this.ctx.strokeRect(theX, theY, 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);
|
|
||||||
|
|
||||||
|
theX += this.radius + 1;
|
||||||
|
theY += this.radius + 1;
|
||||||
|
|
||||||
|
|
||||||
let blok = mainTiles.tiles[this.getBlock(theX, theY)];
|
let blok = mainTiles.tiles[this.getBlock(theX, theY)];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue