Suport staggerIndex-even with staggerAxis-y and staggerAxis-x

This commit is contained in:
Rex 2023-03-25 20:47:45 +08:00
parent 65c0f9f73b
commit bc1fcf7357
3 changed files with 51 additions and 10 deletions

View file

@ -781,19 +781,36 @@ var Tile = new Class({
var len = this.layer.hexSideLength;
var rowWidth, rowHeight;
if ((staggerAxis === 'y') && (staggerIndex === 'odd'))
if (staggerAxis === 'y')
{
rowHeight = ((this.baseHeight - len) / 2 + len);
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
if (staggerIndex === 'odd')
{
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
}
else
{
this.pixelX = this.x * this.baseWidth - this.y % 2 * (this.baseWidth / 2);
}
this.pixelY = this.y * rowHeight;
}
else if ((staggerAxis === 'x') && (staggerIndex === 'odd'))
else if (staggerAxis === 'x')
{
rowWidth = ((this.baseWidth - len) / 2 + len);
this.pixelX = this.x * rowWidth;
this.pixelY = this.y * this.baseHeight + this.x % 2 * (this.baseHeight / 2);
if (staggerIndex === 'odd')
{
this.pixelY = this.y * this.baseHeight + this.x % 2 * (this.baseHeight / 2);
}
else
{
this.pixelY = this.y * this.baseHeight - this.x % 2 * (this.baseHeight / 2);
}
}
}

View file

@ -52,14 +52,21 @@ var HexagonalTileToWorldXY = function (tileX, tileY, point, camera, layer)
var x, y;
if ((this.staggerAxis === 'y') && (this.staggerIndex === 'odd'))
if (this.staggerAxis === 'y')
{
x = worldX + (tileWidth * tileX) + tileWidth;
y = worldY + ((1.5 * tileY) * tileHeightHalf) + tileHeightHalf;
if (tileY % 2 === 0)
{
x -= tileWidthHalf;
if (this.staggerIndex === 'odd')
{
x -= tileWidthHalf;
}
else
{
x += tileWidthHalf;
}
}
}
else if ((this.staggerAxis === 'x') && (this.staggerIndex === 'odd'))
@ -69,7 +76,15 @@ var HexagonalTileToWorldXY = function (tileX, tileY, point, camera, layer)
if (tileX % 2 === 0)
{
y -= tileHeightHalf;
if (this.staggerIndex === 'odd')
{
y -= tileHeightHalf;
}
else
{
y += tileHeightHalf;
}
}
}

View file

@ -59,7 +59,7 @@ var HexagonalWorldToTileXY = function (worldX, worldY, snapToFloor, point, camer
var q, r, s;
// size
if (this.staggerAxis === 'y')
if (layer.staggerAxis === 'y')
{
// x = b0 * tileWidth
// y = tileHeightHalf
@ -99,9 +99,18 @@ var HexagonalWorldToTileXY = function (worldX, worldY, snapToFloor, point, camer
ri = -qi - si;
}
var y = ri;
var x, y;
var x = (y % 2 === 0) ? (ri / 2) + qi : (ri / 2) + qi - 0.5;
y = ri;
if (layer.staggerIndex === 'odd')
{
x = (y % 2 === 0) ? (ri / 2) + qi : (ri / 2) + qi - 0.5;
}
else
{
x = (y % 2 === 0) ? (ri / 2) + qi : (ri / 2) + qi + 0.5;
}
return point.set(x, y);
};