mirror of
https://github.com/photonstorm/phaser
synced 2024-12-23 03:23:42 +00:00
added hexagonal support
This commit is contained in:
parent
406e6eb093
commit
cec71a85ea
19 changed files with 382 additions and 55 deletions
143
dist/phaser-arcade-physics.js
vendored
143
dist/phaser-arcade-physics.js
vendored
|
@ -11919,7 +11919,7 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
|
|||
point.x = WorldToTileX(worldX, snapToFloor, camera, layer, orientation);
|
||||
point.y = WorldToTileY(worldY, snapToFloor, camera, layer, orientation);
|
||||
}
|
||||
else if (orientation === 'isometric' || orientation === 'staggered')
|
||||
else if (orientation === 'isometric' || orientation === 'staggered' || orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
var tileWidth = layer.baseTileWidth;
|
||||
|
@ -11966,15 +11966,27 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
|
|||
}
|
||||
else if (orientation === 'staggered')
|
||||
{
|
||||
// implement world to tile staggered
|
||||
point.y = snapToFloor
|
||||
? Math.floor((worldY / (tileHeight / 2)))
|
||||
: (worldY / (tileHeight / 2));
|
||||
point.x = snapToFloor
|
||||
? Math.floor((worldX - (point.y % 2) * 0.5 * tileWidth) / tileWidth)
|
||||
: (worldX - (worldY % 2) * 0.5 * tileWidth) / tileWidth;
|
||||
? Math.floor((worldX + (point.y % 2) * 0.5 * tileWidth) / tileWidth)
|
||||
: (worldX + (point.y % 2) * 0.5 * tileWidth) / tileWidth;
|
||||
|
||||
}
|
||||
else if (orientation === 'hexagonal')
|
||||
{
|
||||
var sidel = layer.hexSideLength;
|
||||
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
|
||||
|
||||
// similar to staggered, because Tiled uses the oddr representation.
|
||||
point.y = snapToFloor
|
||||
? Math.floor((worldY / rowHeight))
|
||||
: (worldY / rowHeight);
|
||||
point.x = snapToFloor
|
||||
? Math.floor((worldX - (point.y % 2) * 0.5 * tileWidth) / tileWidth)
|
||||
: (worldX - (point.y % 2) * 0.5 * tileWidth) / tileWidth;
|
||||
}
|
||||
}
|
||||
|
||||
return point;
|
||||
|
@ -12714,13 +12726,27 @@ var Tile = new Class({
|
|||
}
|
||||
else if (this.layer.orientation === 'staggered')
|
||||
{
|
||||
var tmap = this.layer.tilemapLayer.tilemap;
|
||||
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
|
||||
this.pixelY = this.y * (this.baseHeight / 2);
|
||||
|
||||
}
|
||||
else if (this.layer.orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
// var tmap = this.layer.tilemapLayer.tilemap;
|
||||
console.log(this.layer.hexSideLength);
|
||||
var sidel = this.layer.hexSideLength;
|
||||
|
||||
var rowHeight = ((this.baseHeight - sidel) / 2 + sidel);
|
||||
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
|
||||
this.pixelY = this.y * rowHeight;
|
||||
|
||||
console.log('hexapix', this.pixelX, this.pixelY);
|
||||
}
|
||||
|
||||
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);
|
||||
|
||||
console.log(this.layer);
|
||||
return this;
|
||||
},
|
||||
|
||||
|
@ -19466,6 +19492,16 @@ var LayerData = new Class({
|
|||
* @since 3.0.0
|
||||
*/
|
||||
this.tilemapLayer = GetFastValue(config, 'tilemapLayer', null);
|
||||
|
||||
/**
|
||||
* Optional : Only for hexagonal tilemaps.
|
||||
* The length of the horizontal sides of the hexagon.
|
||||
* @name Phaser.Tilemaps.MapData#tiles
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.hexSideLength = GetFastValue(config, 'hexSideLength', 0);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -19691,6 +19727,15 @@ var MapData = new Class({
|
|||
* @since 3.0.0
|
||||
*/
|
||||
this.tiles = GetFastValue(config, 'tiles', []);
|
||||
|
||||
/**
|
||||
* Optional : Only for hexagonal tilemaps.
|
||||
* The length of the horizontal sides of the hexagon.
|
||||
* @name Phaser.Tilemaps.MapData#tiles
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.hexSideLength = GetFastValue(config, 'hexSideLength', 0);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -47297,7 +47342,7 @@ var TileToWorldXY = function (tileX, tileY, point, camera, layer)
|
|||
point.x = TileToWorldX(tileX, camera, layer, orientation);
|
||||
point.y = TileToWorldY(tileY, camera, layer, orientation);
|
||||
}
|
||||
else if (orientation === 'isometric' || orientation === 'staggered')
|
||||
else if (orientation === 'isometric' || orientation === 'staggered' || orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
var layerWorldX = 0;
|
||||
|
@ -47320,10 +47365,18 @@ var TileToWorldXY = function (tileX, tileY, point, camera, layer)
|
|||
}
|
||||
else if (orientation === 'staggered')
|
||||
{
|
||||
// todo
|
||||
point.x = layerWorldX + tileX * tileWidth + tileY % 2 * (tileWidth / 2);
|
||||
point.y = layerWorldY + tileY * (tileHeight / 2);
|
||||
}
|
||||
else if (orientation === 'hexagonal')
|
||||
{
|
||||
var sidel = layer.hexSideLength;
|
||||
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
|
||||
|
||||
// similar to staggered, because Tiled uses the oddr representation.
|
||||
point.x = layerWorldX + tileX * tileWidth + tileY % 2 * (tileWidth / 2);
|
||||
point.y = layerWorldY + tileY * rowHeight;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -102659,14 +102712,15 @@ var TileToWorldX = function (tileX, camera, layer)
|
|||
{
|
||||
return layerWorldX + tileX * tileWidth;
|
||||
}
|
||||
else if (orientation === 'isometric')
|
||||
else if (orientation === 'isometric' || orientation === 'staggered' || orientation === 'hexagonal' )
|
||||
{
|
||||
// Not Best Solution ?
|
||||
console.warn('With isometric map types you have to use the TileToWorldXY function.');
|
||||
console.warn('With the current map type you have to use the TileToWorldXY function.');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
module.exports = TileToWorldX;
|
||||
|
@ -102720,6 +102774,18 @@ var TileToWorldY = function (tileY, camera, layer)
|
|||
console.warn('With isometric map types you have to use the TileToWorldXY function.');
|
||||
return null;
|
||||
}
|
||||
else if (orientation === 'staggered')
|
||||
{
|
||||
return layerWorldY + tileY * (tileHeight / 2);
|
||||
}
|
||||
else if (orientation === 'hexagonal')
|
||||
{
|
||||
var sidel = layer.tilemapLayer.tilemap.hexSideLength;
|
||||
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
|
||||
|
||||
// same as staggered
|
||||
return layerWorldY + tileY * rowHeight;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = TileToWorldY;
|
||||
|
@ -102884,10 +102950,25 @@ var WorldToTileY = function (worldY, snapToFloor, camera, layer)
|
|||
}
|
||||
else if (orientation === 'isometric')
|
||||
{
|
||||
console.warn('With isometric map types you have to use the WorldToTileXY function.');
|
||||
console.warn('With standard isometric map types you have to use the WorldToTileXY function.');
|
||||
return null;
|
||||
|
||||
}
|
||||
else if (orientation === 'staggered')
|
||||
{
|
||||
return snapToFloor
|
||||
? Math.floor(worldY / (tileHeight / 2))
|
||||
: worldY / (tileHeight / 2);
|
||||
}
|
||||
else if (orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
var sidel = layer.hexSideLength;
|
||||
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
|
||||
return snapToFloor
|
||||
? Math.floor(worldY / rowHeight)
|
||||
: worldY / rowHeight;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = WorldToTileY;
|
||||
|
@ -103157,11 +103238,15 @@ var ParseJSONTiled = function (name, json, insertNull)
|
|||
{
|
||||
if (json.orientation === 'isometric' || json.orientation === 'staggered')
|
||||
{
|
||||
console.warn('isometric map types are WIP in this version of Phaser');
|
||||
console.warn('Isometric map types are WIP in this version of Phaser');
|
||||
}
|
||||
else if (json.orientation === 'hexagonal')
|
||||
{
|
||||
console.warn('Hexagonal map types are WIP in this version of Phaser');
|
||||
}
|
||||
else if (json.orientation !== 'orthogonal')
|
||||
{
|
||||
console.warn('Only orthogonal and standard isometric map types are supported in this version of Phaser');
|
||||
console.warn('Only orthogonal, hexagonal and isometric map types are supported in this version of Phaser');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -103180,6 +103265,11 @@ var ParseJSONTiled = function (name, json, insertNull)
|
|||
infinite: json.infinite
|
||||
});
|
||||
|
||||
if (mapData.orientation === 'hexagonal')
|
||||
{
|
||||
mapData.hexSideLength = json.hexsidelength;
|
||||
}
|
||||
|
||||
mapData.layers = ParseTileLayers(json, insertNull);
|
||||
mapData.images = ParseImageLayers(json);
|
||||
|
||||
|
@ -103336,6 +103426,10 @@ var ParseTileLayers = function (json, insertNull)
|
|||
orientation: json.orientation
|
||||
});
|
||||
|
||||
if (layerData.orientation === 'hexagonal')
|
||||
{
|
||||
layerData.hexSideLength = json.hexsidelength;
|
||||
}
|
||||
|
||||
for (var c = 0; c < curl.height; c++)
|
||||
{
|
||||
|
@ -103410,6 +103504,11 @@ var ParseTileLayers = function (json, insertNull)
|
|||
properties: GetFastValue(curl, 'properties', {}),
|
||||
orientation: json.orientation
|
||||
});
|
||||
|
||||
if (layerData.orientation === 'hexagonal')
|
||||
{
|
||||
layerData.hexSideLength = json.hexsidelength;
|
||||
}
|
||||
var row = [];
|
||||
|
||||
// Loop through the data field in the JSON.
|
||||
|
@ -104801,6 +104900,15 @@ var Tilemap = new Class({
|
|||
* @since 3.0.0
|
||||
*/
|
||||
this.currentLayerIndex = 0;
|
||||
|
||||
/**
|
||||
* Optional : Only for hexagonal tilemaps.
|
||||
* The length of the horizontal sides of the hexagon.
|
||||
* @name Phaser.Tilemaps.MapData#tiles
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.hexSideLength = mapData.hexSideLength;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -107220,6 +107328,7 @@ var DynamicTilemapLayer = new Class({
|
|||
|
||||
// Link the LayerData with this static tilemap layer
|
||||
this.layer.tilemapLayer = this;
|
||||
console.log('fug',this.layer);
|
||||
|
||||
/**
|
||||
* The Tileset/s associated with this layer.
|
||||
|
@ -175599,7 +175708,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
|||
var inIsoBounds = function () { return true; };
|
||||
if (!tilemapLayer.skipCull && tilemapLayer.scrollFactorX === 1 && tilemapLayer.scrollFactorY === 1)
|
||||
{
|
||||
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
|
||||
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered' || layer.orientation === 'hexagonal')
|
||||
{
|
||||
// Camera world view bounds, snapped for scaled tile size
|
||||
// Cull Padding values are given in tiles, not pixels
|
||||
|
@ -175635,7 +175744,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
|||
var tile;
|
||||
|
||||
|
||||
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
|
||||
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered' || layer.orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
if (renderOrder === 0)
|
||||
|
@ -177434,7 +177543,7 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, src, interpolationPer
|
|||
var frameWidth = 0;
|
||||
var frameHeight = 0;
|
||||
|
||||
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered')
|
||||
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered' || src.layer.orientation === 'hexagonal')
|
||||
{
|
||||
// we use the tileset width and height because in isometric maps the tileset's height is often different from the tilemap's.
|
||||
frameWidth = tileset.tileWidth;
|
||||
|
@ -177577,9 +177686,9 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
|
|||
var width = tile.width;
|
||||
var height = tile.width;
|
||||
|
||||
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered')
|
||||
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered' || src.layer.orientation === 'hexagonal')
|
||||
{
|
||||
// we use the tileset width and height because in isometric maps the tileset's height is often different from the tilemap's.
|
||||
// we use the tileset width and height because in isometric and hexagonal maps the tileset's height is often different from the tilemap's.
|
||||
width = tileset.tileWidth;
|
||||
width = tileset.tileHeight;
|
||||
}
|
||||
|
|
2
dist/phaser-arcade-physics.min.js
vendored
2
dist/phaser-arcade-physics.min.js
vendored
File diff suppressed because one or more lines are too long
143
dist/phaser.js
vendored
143
dist/phaser.js
vendored
|
@ -13843,7 +13843,7 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
|
|||
point.x = WorldToTileX(worldX, snapToFloor, camera, layer, orientation);
|
||||
point.y = WorldToTileY(worldY, snapToFloor, camera, layer, orientation);
|
||||
}
|
||||
else if (orientation === 'isometric' || orientation === 'staggered')
|
||||
else if (orientation === 'isometric' || orientation === 'staggered' || orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
var tileWidth = layer.baseTileWidth;
|
||||
|
@ -13890,15 +13890,27 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
|
|||
}
|
||||
else if (orientation === 'staggered')
|
||||
{
|
||||
// implement world to tile staggered
|
||||
point.y = snapToFloor
|
||||
? Math.floor((worldY / (tileHeight / 2)))
|
||||
: (worldY / (tileHeight / 2));
|
||||
point.x = snapToFloor
|
||||
? Math.floor((worldX - (point.y % 2) * 0.5 * tileWidth) / tileWidth)
|
||||
: (worldX - (worldY % 2) * 0.5 * tileWidth) / tileWidth;
|
||||
? Math.floor((worldX + (point.y % 2) * 0.5 * tileWidth) / tileWidth)
|
||||
: (worldX + (point.y % 2) * 0.5 * tileWidth) / tileWidth;
|
||||
|
||||
}
|
||||
else if (orientation === 'hexagonal')
|
||||
{
|
||||
var sidel = layer.hexSideLength;
|
||||
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
|
||||
|
||||
// similar to staggered, because Tiled uses the oddr representation.
|
||||
point.y = snapToFloor
|
||||
? Math.floor((worldY / rowHeight))
|
||||
: (worldY / rowHeight);
|
||||
point.x = snapToFloor
|
||||
? Math.floor((worldX - (point.y % 2) * 0.5 * tileWidth) / tileWidth)
|
||||
: (worldX - (point.y % 2) * 0.5 * tileWidth) / tileWidth;
|
||||
}
|
||||
}
|
||||
|
||||
return point;
|
||||
|
@ -14638,13 +14650,27 @@ var Tile = new Class({
|
|||
}
|
||||
else if (this.layer.orientation === 'staggered')
|
||||
{
|
||||
var tmap = this.layer.tilemapLayer.tilemap;
|
||||
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
|
||||
this.pixelY = this.y * (this.baseHeight / 2);
|
||||
|
||||
}
|
||||
else if (this.layer.orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
// var tmap = this.layer.tilemapLayer.tilemap;
|
||||
console.log(this.layer.hexSideLength);
|
||||
var sidel = this.layer.hexSideLength;
|
||||
|
||||
var rowHeight = ((this.baseHeight - sidel) / 2 + sidel);
|
||||
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
|
||||
this.pixelY = this.y * rowHeight;
|
||||
|
||||
console.log('hexapix', this.pixelX, this.pixelY);
|
||||
}
|
||||
|
||||
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);
|
||||
|
||||
console.log(this.layer);
|
||||
return this;
|
||||
},
|
||||
|
||||
|
@ -22218,6 +22244,16 @@ var LayerData = new Class({
|
|||
* @since 3.0.0
|
||||
*/
|
||||
this.tilemapLayer = GetFastValue(config, 'tilemapLayer', null);
|
||||
|
||||
/**
|
||||
* Optional : Only for hexagonal tilemaps.
|
||||
* The length of the horizontal sides of the hexagon.
|
||||
* @name Phaser.Tilemaps.MapData#tiles
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.hexSideLength = GetFastValue(config, 'hexSideLength', 0);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -22443,6 +22479,15 @@ var MapData = new Class({
|
|||
* @since 3.0.0
|
||||
*/
|
||||
this.tiles = GetFastValue(config, 'tiles', []);
|
||||
|
||||
/**
|
||||
* Optional : Only for hexagonal tilemaps.
|
||||
* The length of the horizontal sides of the hexagon.
|
||||
* @name Phaser.Tilemaps.MapData#tiles
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.hexSideLength = GetFastValue(config, 'hexSideLength', 0);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -51587,7 +51632,7 @@ var TileToWorldXY = function (tileX, tileY, point, camera, layer)
|
|||
point.x = TileToWorldX(tileX, camera, layer, orientation);
|
||||
point.y = TileToWorldY(tileY, camera, layer, orientation);
|
||||
}
|
||||
else if (orientation === 'isometric' || orientation === 'staggered')
|
||||
else if (orientation === 'isometric' || orientation === 'staggered' || orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
var layerWorldX = 0;
|
||||
|
@ -51610,10 +51655,18 @@ var TileToWorldXY = function (tileX, tileY, point, camera, layer)
|
|||
}
|
||||
else if (orientation === 'staggered')
|
||||
{
|
||||
// todo
|
||||
point.x = layerWorldX + tileX * tileWidth + tileY % 2 * (tileWidth / 2);
|
||||
point.y = layerWorldY + tileY * (tileHeight / 2);
|
||||
}
|
||||
else if (orientation === 'hexagonal')
|
||||
{
|
||||
var sidel = layer.hexSideLength;
|
||||
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
|
||||
|
||||
// similar to staggered, because Tiled uses the oddr representation.
|
||||
point.x = layerWorldX + tileX * tileWidth + tileY % 2 * (tileWidth / 2);
|
||||
point.y = layerWorldY + tileY * rowHeight;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -107325,14 +107378,15 @@ var TileToWorldX = function (tileX, camera, layer)
|
|||
{
|
||||
return layerWorldX + tileX * tileWidth;
|
||||
}
|
||||
else if (orientation === 'isometric')
|
||||
else if (orientation === 'isometric' || orientation === 'staggered' || orientation === 'hexagonal' )
|
||||
{
|
||||
// Not Best Solution ?
|
||||
console.warn('With isometric map types you have to use the TileToWorldXY function.');
|
||||
console.warn('With the current map type you have to use the TileToWorldXY function.');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
module.exports = TileToWorldX;
|
||||
|
@ -107386,6 +107440,18 @@ var TileToWorldY = function (tileY, camera, layer)
|
|||
console.warn('With isometric map types you have to use the TileToWorldXY function.');
|
||||
return null;
|
||||
}
|
||||
else if (orientation === 'staggered')
|
||||
{
|
||||
return layerWorldY + tileY * (tileHeight / 2);
|
||||
}
|
||||
else if (orientation === 'hexagonal')
|
||||
{
|
||||
var sidel = layer.tilemapLayer.tilemap.hexSideLength;
|
||||
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
|
||||
|
||||
// same as staggered
|
||||
return layerWorldY + tileY * rowHeight;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = TileToWorldY;
|
||||
|
@ -107550,10 +107616,25 @@ var WorldToTileY = function (worldY, snapToFloor, camera, layer)
|
|||
}
|
||||
else if (orientation === 'isometric')
|
||||
{
|
||||
console.warn('With isometric map types you have to use the WorldToTileXY function.');
|
||||
console.warn('With standard isometric map types you have to use the WorldToTileXY function.');
|
||||
return null;
|
||||
|
||||
}
|
||||
else if (orientation === 'staggered')
|
||||
{
|
||||
return snapToFloor
|
||||
? Math.floor(worldY / (tileHeight / 2))
|
||||
: worldY / (tileHeight / 2);
|
||||
}
|
||||
else if (orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
var sidel = layer.hexSideLength;
|
||||
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
|
||||
return snapToFloor
|
||||
? Math.floor(worldY / rowHeight)
|
||||
: worldY / rowHeight;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = WorldToTileY;
|
||||
|
@ -107823,11 +107904,15 @@ var ParseJSONTiled = function (name, json, insertNull)
|
|||
{
|
||||
if (json.orientation === 'isometric' || json.orientation === 'staggered')
|
||||
{
|
||||
console.warn('isometric map types are WIP in this version of Phaser');
|
||||
console.warn('Isometric map types are WIP in this version of Phaser');
|
||||
}
|
||||
else if (json.orientation === 'hexagonal')
|
||||
{
|
||||
console.warn('Hexagonal map types are WIP in this version of Phaser');
|
||||
}
|
||||
else if (json.orientation !== 'orthogonal')
|
||||
{
|
||||
console.warn('Only orthogonal and standard isometric map types are supported in this version of Phaser');
|
||||
console.warn('Only orthogonal, hexagonal and isometric map types are supported in this version of Phaser');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -107846,6 +107931,11 @@ var ParseJSONTiled = function (name, json, insertNull)
|
|||
infinite: json.infinite
|
||||
});
|
||||
|
||||
if (mapData.orientation === 'hexagonal')
|
||||
{
|
||||
mapData.hexSideLength = json.hexsidelength;
|
||||
}
|
||||
|
||||
mapData.layers = ParseTileLayers(json, insertNull);
|
||||
mapData.images = ParseImageLayers(json);
|
||||
|
||||
|
@ -108002,6 +108092,10 @@ var ParseTileLayers = function (json, insertNull)
|
|||
orientation: json.orientation
|
||||
});
|
||||
|
||||
if (layerData.orientation === 'hexagonal')
|
||||
{
|
||||
layerData.hexSideLength = json.hexsidelength;
|
||||
}
|
||||
|
||||
for (var c = 0; c < curl.height; c++)
|
||||
{
|
||||
|
@ -108076,6 +108170,11 @@ var ParseTileLayers = function (json, insertNull)
|
|||
properties: GetFastValue(curl, 'properties', {}),
|
||||
orientation: json.orientation
|
||||
});
|
||||
|
||||
if (layerData.orientation === 'hexagonal')
|
||||
{
|
||||
layerData.hexSideLength = json.hexsidelength;
|
||||
}
|
||||
var row = [];
|
||||
|
||||
// Loop through the data field in the JSON.
|
||||
|
@ -109467,6 +109566,15 @@ var Tilemap = new Class({
|
|||
* @since 3.0.0
|
||||
*/
|
||||
this.currentLayerIndex = 0;
|
||||
|
||||
/**
|
||||
* Optional : Only for hexagonal tilemaps.
|
||||
* The length of the horizontal sides of the hexagon.
|
||||
* @name Phaser.Tilemaps.MapData#tiles
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.hexSideLength = mapData.hexSideLength;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -111886,6 +111994,7 @@ var DynamicTilemapLayer = new Class({
|
|||
|
||||
// Link the LayerData with this static tilemap layer
|
||||
this.layer.tilemapLayer = this;
|
||||
console.log('fug',this.layer);
|
||||
|
||||
/**
|
||||
* The Tileset/s associated with this layer.
|
||||
|
@ -183327,7 +183436,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
|||
var inIsoBounds = function () { return true; };
|
||||
if (!tilemapLayer.skipCull && tilemapLayer.scrollFactorX === 1 && tilemapLayer.scrollFactorY === 1)
|
||||
{
|
||||
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
|
||||
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered' || layer.orientation === 'hexagonal')
|
||||
{
|
||||
// Camera world view bounds, snapped for scaled tile size
|
||||
// Cull Padding values are given in tiles, not pixels
|
||||
|
@ -183363,7 +183472,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
|||
var tile;
|
||||
|
||||
|
||||
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
|
||||
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered' || layer.orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
if (renderOrder === 0)
|
||||
|
@ -185162,7 +185271,7 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, src, interpolationPer
|
|||
var frameWidth = 0;
|
||||
var frameHeight = 0;
|
||||
|
||||
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered')
|
||||
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered' || src.layer.orientation === 'hexagonal')
|
||||
{
|
||||
// we use the tileset width and height because in isometric maps the tileset's height is often different from the tilemap's.
|
||||
frameWidth = tileset.tileWidth;
|
||||
|
@ -185305,9 +185414,9 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
|
|||
var width = tile.width;
|
||||
var height = tile.width;
|
||||
|
||||
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered')
|
||||
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered' || src.layer.orientation === 'hexagonal')
|
||||
{
|
||||
// we use the tileset width and height because in isometric maps the tileset's height is often different from the tilemap's.
|
||||
// we use the tileset width and height because in isometric and hexagonal maps the tileset's height is often different from the tilemap's.
|
||||
width = tileset.tileWidth;
|
||||
width = tileset.tileHeight;
|
||||
}
|
||||
|
|
2
dist/phaser.min.js
vendored
2
dist/phaser.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -725,13 +725,27 @@ var Tile = new Class({
|
|||
}
|
||||
else if (this.layer.orientation === 'staggered')
|
||||
{
|
||||
var tmap = this.layer.tilemapLayer.tilemap;
|
||||
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
|
||||
this.pixelY = this.y * (this.baseHeight / 2);
|
||||
|
||||
}
|
||||
else if (this.layer.orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
// var tmap = this.layer.tilemapLayer.tilemap;
|
||||
console.log(this.layer.hexSideLength);
|
||||
var sidel = this.layer.hexSideLength;
|
||||
|
||||
var rowHeight = ((this.baseHeight - sidel) / 2 + sidel);
|
||||
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
|
||||
this.pixelY = this.y * rowHeight;
|
||||
|
||||
console.log('hexapix', this.pixelX, this.pixelY);
|
||||
}
|
||||
|
||||
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);
|
||||
|
||||
console.log(this.layer);
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
|
@ -251,6 +251,15 @@ var Tilemap = new Class({
|
|||
* @since 3.0.0
|
||||
*/
|
||||
this.currentLayerIndex = 0;
|
||||
|
||||
/**
|
||||
* Optional : Only for hexagonal tilemaps.
|
||||
* The length of the horizontal sides of the hexagon.
|
||||
* @name Phaser.Tilemaps.MapData#tiles
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.hexSideLength = mapData.hexSideLength;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,7 +49,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
|||
var inIsoBounds = function () { return true; };
|
||||
if (!tilemapLayer.skipCull && tilemapLayer.scrollFactorX === 1 && tilemapLayer.scrollFactorY === 1)
|
||||
{
|
||||
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
|
||||
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered' || layer.orientation === 'hexagonal')
|
||||
{
|
||||
// Camera world view bounds, snapped for scaled tile size
|
||||
// Cull Padding values are given in tiles, not pixels
|
||||
|
@ -85,7 +85,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
|||
var tile;
|
||||
|
||||
|
||||
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
|
||||
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered' || layer.orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
if (renderOrder === 0)
|
||||
|
|
|
@ -38,14 +38,15 @@ var TileToWorldX = function (tileX, camera, layer)
|
|||
{
|
||||
return layerWorldX + tileX * tileWidth;
|
||||
}
|
||||
else if (orientation === 'isometric')
|
||||
else if (orientation === 'isometric' || orientation === 'staggered' || orientation === 'hexagonal' )
|
||||
{
|
||||
// Not Best Solution ?
|
||||
console.warn('With isometric map types you have to use the TileToWorldXY function.');
|
||||
console.warn('With the current map type you have to use the TileToWorldXY function.');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
module.exports = TileToWorldX;
|
||||
|
|
|
@ -43,7 +43,7 @@ var TileToWorldXY = function (tileX, tileY, point, camera, layer)
|
|||
point.x = TileToWorldX(tileX, camera, layer, orientation);
|
||||
point.y = TileToWorldY(tileY, camera, layer, orientation);
|
||||
}
|
||||
else if (orientation === 'isometric' || orientation === 'staggered')
|
||||
else if (orientation === 'isometric' || orientation === 'staggered' || orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
var layerWorldX = 0;
|
||||
|
@ -66,10 +66,18 @@ var TileToWorldXY = function (tileX, tileY, point, camera, layer)
|
|||
}
|
||||
else if (orientation === 'staggered')
|
||||
{
|
||||
// todo
|
||||
point.x = layerWorldX + tileX * tileWidth + tileY % 2 * (tileWidth / 2);
|
||||
point.y = layerWorldY + tileY * (tileHeight / 2);
|
||||
}
|
||||
else if (orientation === 'hexagonal')
|
||||
{
|
||||
var sidel = layer.hexSideLength;
|
||||
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
|
||||
|
||||
// similar to staggered, because Tiled uses the oddr representation.
|
||||
point.x = layerWorldX + tileX * tileWidth + tileY % 2 * (tileWidth / 2);
|
||||
point.y = layerWorldY + tileY * rowHeight;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -42,6 +42,18 @@ var TileToWorldY = function (tileY, camera, layer)
|
|||
console.warn('With isometric map types you have to use the TileToWorldXY function.');
|
||||
return null;
|
||||
}
|
||||
else if (orientation === 'staggered')
|
||||
{
|
||||
return layerWorldY + tileY * (tileHeight / 2);
|
||||
}
|
||||
else if (orientation === 'hexagonal')
|
||||
{
|
||||
var sidel = layer.tilemapLayer.tilemap.hexSideLength;
|
||||
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
|
||||
|
||||
// same as staggered
|
||||
return layerWorldY + tileY * rowHeight;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = TileToWorldY;
|
||||
|
|
|
@ -36,7 +36,7 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
|
|||
point.x = WorldToTileX(worldX, snapToFloor, camera, layer, orientation);
|
||||
point.y = WorldToTileY(worldY, snapToFloor, camera, layer, orientation);
|
||||
}
|
||||
else if (orientation === 'isometric' || orientation === 'staggered')
|
||||
else if (orientation === 'isometric' || orientation === 'staggered' || orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
var tileWidth = layer.baseTileWidth;
|
||||
|
@ -83,15 +83,27 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
|
|||
}
|
||||
else if (orientation === 'staggered')
|
||||
{
|
||||
// implement world to tile staggered
|
||||
point.y = snapToFloor
|
||||
? Math.floor((worldY / (tileHeight / 2)))
|
||||
: (worldY / (tileHeight / 2));
|
||||
point.x = snapToFloor
|
||||
? Math.floor((worldX + (point.y % 2) * 0.5 * tileWidth) / tileWidth)
|
||||
: (worldX + (worldY % 2) * 0.5 * tileWidth) / tileWidth;
|
||||
: (worldX + (point.y % 2) * 0.5 * tileWidth) / tileWidth;
|
||||
|
||||
}
|
||||
else if (orientation === 'hexagonal')
|
||||
{
|
||||
var sidel = layer.hexSideLength;
|
||||
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
|
||||
|
||||
// similar to staggered, because Tiled uses the oddr representation.
|
||||
point.y = snapToFloor
|
||||
? Math.floor((worldY / rowHeight))
|
||||
: (worldY / rowHeight);
|
||||
point.x = snapToFloor
|
||||
? Math.floor((worldX - (point.y % 2) * 0.5 * tileWidth) / tileWidth)
|
||||
: (worldX - (point.y % 2) * 0.5 * tileWidth) / tileWidth;
|
||||
}
|
||||
}
|
||||
|
||||
return point;
|
||||
|
|
|
@ -46,10 +46,25 @@ var WorldToTileY = function (worldY, snapToFloor, camera, layer)
|
|||
}
|
||||
else if (orientation === 'isometric')
|
||||
{
|
||||
console.warn('With isometric map types you have to use the WorldToTileXY function.');
|
||||
console.warn('With standard isometric map types you have to use the WorldToTileXY function.');
|
||||
return null;
|
||||
|
||||
}
|
||||
else if (orientation === 'staggered')
|
||||
{
|
||||
return snapToFloor
|
||||
? Math.floor(worldY / (tileHeight / 2))
|
||||
: worldY / (tileHeight / 2);
|
||||
}
|
||||
else if (orientation === 'hexagonal')
|
||||
{
|
||||
|
||||
var sidel = layer.hexSideLength;
|
||||
var rowHeight = ((tileHeight - sidel) / 2 + sidel);
|
||||
return snapToFloor
|
||||
? Math.floor(worldY / rowHeight)
|
||||
: worldY / rowHeight;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = WorldToTileY;
|
||||
|
|
|
@ -112,6 +112,7 @@ var DynamicTilemapLayer = new Class({
|
|||
|
||||
// Link the LayerData with this static tilemap layer
|
||||
this.layer.tilemapLayer = this;
|
||||
console.log('fug',this.layer);
|
||||
|
||||
/**
|
||||
* The Tileset/s associated with this layer.
|
||||
|
|
|
@ -92,9 +92,9 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
|
|||
var width = tile.width;
|
||||
var height = tile.width;
|
||||
|
||||
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered')
|
||||
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered' || src.layer.orientation === 'hexagonal')
|
||||
{
|
||||
// we use the tileset width and height because in isometric maps the tileset's height is often different from the tilemap's.
|
||||
// we use the tileset width and height because in isometric and hexagonal maps the tileset's height is often different from the tilemap's.
|
||||
width = tileset.tileWidth;
|
||||
width = tileset.tileHeight;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, src, interpolationPer
|
|||
var frameWidth = 0;
|
||||
var frameHeight = 0;
|
||||
|
||||
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered')
|
||||
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered' || src.layer.orientation === 'hexagonal')
|
||||
{
|
||||
// we use the tileset width and height because in isometric maps the tileset's height is often different from the tilemap's.
|
||||
frameWidth = tileset.tileWidth;
|
||||
|
|
|
@ -216,6 +216,16 @@ var LayerData = new Class({
|
|||
* @since 3.0.0
|
||||
*/
|
||||
this.tilemapLayer = GetFastValue(config, 'tilemapLayer', null);
|
||||
|
||||
/**
|
||||
* Optional : Only for hexagonal tilemaps.
|
||||
* The length of the horizontal sides of the hexagon.
|
||||
* @name Phaser.Tilemaps.MapData#tiles
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.hexSideLength = GetFastValue(config, 'hexSideLength', 0);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -212,6 +212,15 @@ var MapData = new Class({
|
|||
* @since 3.0.0
|
||||
*/
|
||||
this.tiles = GetFastValue(config, 'tiles', []);
|
||||
|
||||
/**
|
||||
* Optional : Only for hexagonal tilemaps.
|
||||
* The length of the horizontal sides of the hexagon.
|
||||
* @name Phaser.Tilemaps.MapData#tiles
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.hexSideLength = GetFastValue(config, 'hexSideLength', 0);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -34,11 +34,15 @@ var ParseJSONTiled = function (name, json, insertNull)
|
|||
{
|
||||
if (json.orientation === 'isometric' || json.orientation === 'staggered')
|
||||
{
|
||||
console.warn('isometric map types are WIP in this version of Phaser');
|
||||
console.warn('Isometric map types are WIP in this version of Phaser');
|
||||
}
|
||||
else if (json.orientation === 'hexagonal')
|
||||
{
|
||||
console.warn('Hexagonal map types are WIP in this version of Phaser');
|
||||
}
|
||||
else if (json.orientation !== 'orthogonal')
|
||||
{
|
||||
console.warn('Only orthogonal and standard isometric map types are supported in this version of Phaser');
|
||||
console.warn('Only orthogonal, hexagonal and isometric map types are supported in this version of Phaser');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -57,6 +61,11 @@ var ParseJSONTiled = function (name, json, insertNull)
|
|||
infinite: json.infinite
|
||||
});
|
||||
|
||||
if (mapData.orientation === 'hexagonal')
|
||||
{
|
||||
mapData.hexSideLength = json.hexsidelength;
|
||||
}
|
||||
|
||||
mapData.layers = ParseTileLayers(json, insertNull);
|
||||
mapData.images = ParseImageLayers(json);
|
||||
|
||||
|
|
|
@ -131,6 +131,10 @@ var ParseTileLayers = function (json, insertNull)
|
|||
orientation: json.orientation
|
||||
});
|
||||
|
||||
if (layerData.orientation === 'hexagonal')
|
||||
{
|
||||
layerData.hexSideLength = json.hexsidelength;
|
||||
}
|
||||
|
||||
for (var c = 0; c < curl.height; c++)
|
||||
{
|
||||
|
@ -205,6 +209,11 @@ var ParseTileLayers = function (json, insertNull)
|
|||
properties: GetFastValue(curl, 'properties', {}),
|
||||
orientation: json.orientation
|
||||
});
|
||||
|
||||
if (layerData.orientation === 'hexagonal')
|
||||
{
|
||||
layerData.hexSideLength = json.hexsidelength;
|
||||
}
|
||||
var row = [];
|
||||
|
||||
// Loop through the data field in the JSON.
|
||||
|
|
Loading…
Reference in a new issue