Skip to content

Commit a7d4816

Browse files
committed
added staggered support
1 parent 9780592 commit a7d4816

12 files changed

Lines changed: 204 additions & 131 deletions

dist/phaser-arcade-physics.js

Lines changed: 73 additions & 53 deletions
Large diffs are not rendered by default.

dist/phaser-arcade-physics.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/phaser.js

Lines changed: 73 additions & 53 deletions
Large diffs are not rendered by default.

dist/phaser.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"buildfb": "webpack --config config/webpack.fb.config.js",
2323
"watchfb": "webpack --config config/webpack.fb.config.js --watch",
2424
"dist": "webpack --config config/webpack.dist.config.js",
25+
"distT": "webpack --config config/webpack.dist.config.js && npm run toT",
26+
"toT": "@powershell Copy-Item ./dist/phaser.min.js ../phasertest/phaser.min.js",
2527
"distfb": "webpack --config config/webpack.fb.dist.config.js",
2628
"distfull": "npm run dist && npm run distfb",
2729
"plugin.cam3d": "webpack --config plugins/camera3d/webpack.config.js",

src/tilemaps/Tile.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,6 @@ var Tile = new Class({
714714
this.pixelX = this.x * this.baseWidth;
715715
this.pixelY = this.y * this.baseHeight;
716716

717-
// console.log("orthopix "+this.pixelX+","+this.pixelY)
718717
}
719718
else if (this.layer.orientation === 'isometric')
720719
{
@@ -723,11 +722,12 @@ var Tile = new Class({
723722
this.pixelX = (this.x - this.y) * this.baseWidth * 0.5;
724723
this.pixelY = (this.x + this.y) * this.baseHeight * 0.5;
725724

726-
// console.log("isopix from",this.x, this.y,"to", this.pixelX+","+this.pixelY)
727725
}
728-
else
726+
else if (this.layer.orientation === 'staggered')
729727
{
730-
// console.warn("this map orientation is is.layer.orientation)
728+
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
729+
this.pixelY = this.y * (this.baseHeight / 2);
730+
731731
}
732732

733733
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);

src/tilemaps/components/CullTiles.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
4949
var inIsoBounds = function () { return true; };
5050
if (!tilemapLayer.skipCull && tilemapLayer.scrollFactorX === 1 && tilemapLayer.scrollFactorY === 1)
5151
{
52-
if (layer.orientation === 'orthogonal')
52+
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
5353
{
5454
// Camera world view bounds, snapped for scaled tile size
5555
// Cull Padding values are given in tiles, not pixels
@@ -62,6 +62,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
6262
drawLeft = Math.max(0, boundsLeft);
6363
drawRight = Math.min(mapWidth, boundsRight);
6464
drawTop = Math.max(0, boundsTop);
65+
6566
drawBottom = Math.min(mapHeight, boundsBottom);
6667
}
6768
else if (layer.orientation === 'isometric')
@@ -84,7 +85,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
8485
var tile;
8586

8687

87-
if (layer.orientation === 'orthogonal')
88+
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
8889
{
8990

9091
if (renderOrder === 0)

src/tilemaps/components/TileToWorldXY.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var TileToWorldXY = function (tileX, tileY, point, camera, layer)
4343
point.x = TileToWorldX(tileX, camera, layer, orientation);
4444
point.y = TileToWorldY(tileY, camera, layer, orientation);
4545
}
46-
else if (orientation === 'isometric')
46+
else if (orientation === 'isometric' || orientation === 'staggered')
4747
{
4848

4949
var layerWorldX = 0;
@@ -59,9 +59,18 @@ var TileToWorldXY = function (tileX, tileY, point, camera, layer)
5959
}
6060

6161

62-
63-
point.x = layerWorldX + (tileX - tileY) * (tileWidth / 2);
64-
point.y = layerWorldY + (tileX + tileY) * (tileHeight / 2);
62+
if (orientation === 'isometric')
63+
{
64+
point.x = layerWorldX + (tileX - tileY) * (tileWidth / 2);
65+
point.y = layerWorldY + (tileX + tileY) * (tileHeight / 2);
66+
}
67+
else if (orientation === 'staggered')
68+
{
69+
// todo
70+
point.x = layerWorldX + tileX * tileWidth + tileY % 2 * (tileWidth / 2);
71+
point.y = layerWorldY + tileY * (tileHeight / 2);
72+
}
73+
6574

6675
}
6776

src/tilemaps/components/WorldToTileXY.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
3636
point.x = WorldToTileX(worldX, snapToFloor, camera, layer, orientation);
3737
point.y = WorldToTileY(worldY, snapToFloor, camera, layer, orientation);
3838
}
39-
else if (orientation === 'isometric')
39+
else if (orientation === 'isometric' || orientation === 'staggered')
4040
{
4141

4242
var tileWidth = layer.baseTileWidth;
@@ -61,18 +61,39 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
6161

6262
tileWidth *= tilemapLayer.scaleX;
6363
}
64+
65+
if (orientation === 'isometric')
66+
{
67+
point.x = snapToFloor
68+
? Math.floor((worldX / (tileWidth / 2) + worldY / (tileHeight / 2)) / 2)
69+
: ((worldX / (tileWidth / 2) + worldY / (tileHeight / 2)) / 2);
6470

65-
point.x = snapToFloor
66-
? Math.floor((worldX / (tileWidth / 2) + worldY / (tileHeight / 2)) / 2)
67-
: ((worldX / (tileWidth / 2) + worldY / (tileHeight / 2)) / 2);
68-
69-
point.y = snapToFloor
70-
? Math.floor((worldY / (tileHeight / 2) - worldX / (tileWidth / 2)) / 2)
71-
: ((worldY / (tileHeight / 2) - worldX / (tileWidth / 2)) / 2);
71+
point.y = snapToFloor
72+
? Math.floor((worldY / (tileHeight / 2) - worldX / (tileWidth / 2)) / 2)
73+
: ((worldY / (tileHeight / 2) - worldX / (tileWidth / 2)) / 2);
74+
}
75+
if (orientation === 'orthogonal')
76+
{
77+
point.x = snapToFloor
78+
? Math.floor(worldX / tileWidth)
79+
: worldX / tileWidth;
80+
point.y = snapToFloor
81+
? Math.floor(worldY / tileHeight)
82+
: worldY / tileHeight;
83+
}
84+
else if (orientation === 'staggered')
85+
{
86+
// implement world to tile staggered
87+
point.y = snapToFloor
88+
? Math.floor((worldY / (tileHeight / 2)))
89+
: (worldY / (tileHeight / 2));
90+
point.x = snapToFloor
91+
? Math.floor((worldX / tileWidth) - (point.y % 2))
92+
: (worldX / tileWidth) - (point.y % 2);
93+
94+
}
7295
}
7396

74-
75-
7697
return point;
7798
};
7899

src/tilemaps/dynamiclayer/DynamicTilemapLayerCanvasRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
9292
var width = tile.width;
9393
var height = tile.width;
9494

95-
if (src.layer.orientation === 'isometric')
95+
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered')
9696
{
9797
// we use the tileset width and height because in isometric maps the tileset's height is often different from the tilemap's.
9898
width = tileset.tileWidth;

0 commit comments

Comments
 (0)