added staggered support

This commit is contained in:
Svipal 2020-03-14 10:11:04 +01:00
parent 9780592a90
commit a7d4816564
12 changed files with 202 additions and 129 deletions

View file

@ -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')
else if (orientation === 'isometric' || orientation === 'staggered')
{
var tileWidth = layer.baseTileWidth;
@ -11945,6 +11945,8 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
tileWidth *= tilemapLayer.scaleX;
}
if (orientation === 'isometric')
{
point.x = snapToFloor
? Math.floor((worldX / (tileWidth / 2) + worldY / (tileHeight / 2)) / 2)
: ((worldX / (tileWidth / 2) + worldY / (tileHeight / 2)) / 2);
@ -11953,8 +11955,27 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
? Math.floor((worldY / (tileHeight / 2) - worldX / (tileWidth / 2)) / 2)
: ((worldY / (tileHeight / 2) - worldX / (tileWidth / 2)) / 2);
}
if (orientation === 'orthogonal')
{
point.x = snapToFloor
? Math.floor(worldX / tileWidth)
: worldX / tileWidth;
point.y = snapToFloor
? Math.floor(worldY / tileHeight)
: worldY / tileHeight;
}
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 / tileWidth) - (point.y % 2))
: (worldX / tileWidth) - (point.y % 2);
}
}
return point;
};
@ -12004,7 +12025,6 @@ var Rectangle = __webpack_require__(439);
* support multiple tileset sizes within one map, but they are still placed at intervals of the
* base tile height.
*/
var Tile = new Class({
Mixins: [
@ -12080,7 +12100,7 @@ var Tile = new Class({
* @type {integer}
* @since 3.0.0
*/
this.baseWidth = (baseWidth !== undefined && !baseWidth.isNaN()) ? baseWidth : width;
this.baseWidth = (baseWidth !== undefined) ? baseWidth : width;
/**
* The map's base height of a tile in pixels. Tiled maps support multiple tileset sizes
@ -12090,7 +12110,7 @@ var Tile = new Class({
* @type {integer}
* @since 3.0.0
*/
this.baseHeight = (baseHeight !== undefined && !baseWidth.isNaN()) ? baseHeight : height;
this.baseHeight = (baseHeight !== undefined) ? baseHeight : height;
/**
* The x coordinate of the top left of this tile in pixels. This is relative to the top left
@ -12243,7 +12263,6 @@ var Tile = new Class({
* @since 3.0.0
*/
this.physics = {};
},
/**
@ -12684,7 +12703,6 @@ var Tile = new Class({
this.pixelX = this.x * this.baseWidth;
this.pixelY = this.y * this.baseHeight;
// console.log("orthopix "+this.pixelX+","+this.pixelY)
}
else if (this.layer.orientation === 'isometric')
{
@ -12693,11 +12711,12 @@ var Tile = new Class({
this.pixelX = (this.x - this.y) * this.baseWidth * 0.5;
this.pixelY = (this.x + this.y) * this.baseHeight * 0.5;
// console.log("isopix from",this.x, this.y,"to", this.pixelX+","+this.pixelY)
}
else
else if (this.layer.orientation === 'staggered')
{
// console.warn("this map orientation is is.layer.orientation)
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
this.pixelY = this.y * (this.baseHeight / 2);
}
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);
@ -19349,7 +19368,6 @@ var LayerData = new Class({
*/
this.orientation = GetFastValue(config, 'orientation', 'orthogonal');
/**
* The width in pixels of the entire layer.
*
@ -19448,8 +19466,6 @@ var LayerData = new Class({
* @since 3.0.0
*/
this.tilemapLayer = GetFastValue(config, 'tilemapLayer', null);
}
});
@ -26596,9 +26612,7 @@ var GetTileAt = function (tileX, tileY, nonNull, layer)
else
{
return tile;
}
}
else
{
@ -47283,7 +47297,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')
else if (orientation === 'isometric' || orientation === 'staggered')
{
var layerWorldX = 0;
@ -47299,9 +47313,18 @@ var TileToWorldXY = function (tileX, tileY, point, camera, layer)
}
if (orientation === 'isometric')
{
point.x = layerWorldX + (tileX - tileY) * (tileWidth / 2);
point.y = layerWorldY + (tileX + tileY) * (tileHeight / 2);
}
else if (orientation === 'staggered')
{
// todo
point.x = layerWorldX + tileX * tileWidth + tileY % 2 * (tileWidth / 2);
point.y = layerWorldY + tileY * (tileHeight / 2);
}
}
@ -47354,7 +47377,6 @@ var PutTileAt = function (tile, tileX, tileY, recalculateFaces, layer)
if (tile instanceof Tile)
{
if (layer.data[tileY][tileX] === null)
{
layer.data[tileY][tileX] = new Tile(layer, tile.index, tileX, tileY, layer.tileWidth, layer.tileHeight);
@ -47366,7 +47388,6 @@ var PutTileAt = function (tile, tileX, tileY, recalculateFaces, layer)
var index = tile;
if (layer.data[tileY][tileX] === null)
{
layer.data[tileY][tileX] = new Tile(layer, index, tileX, tileY, layer.tileWidth, layer.tileHeight);
}
else
@ -101462,6 +101483,7 @@ module.exports = rbush;
var TileIntersectsBody = function (tileWorldRect, body)
{
// Currently, all bodies are treated as rectangles when colliding with a Tile.
return !(
body.right <= tileWorldRect.left ||
body.bottom <= tileWorldRect.top ||
@ -102633,7 +102655,6 @@ var TileToWorldX = function (tileX, camera, layer)
tileWidth *= tilemapLayer.scaleX;
}
if (orientation === 'orthogonal')
{
return layerWorldX + tileX * tileWidth;
@ -103134,14 +103155,13 @@ var AssignTileProperties = __webpack_require__(489);
*/
var ParseJSONTiled = function (name, json, insertNull)
{
if (json.orientation === 'isometric')
if (json.orientation === 'isometric' || json.orientation === 'staggered')
{
console.warn('isometric map types are WIP in this version of Phaser');
}
else if (json.orientation !== 'orthogonal')
{
console.warn('Only orthogonal map types are supported in this version of Phaser');
console.warn('Only orthogonal and standard isometric map types are supported in this version of Phaser');
return null;
}
@ -107243,9 +107263,9 @@ var DynamicTilemapLayer = new Class({
*
* @name Phaser.Tilemaps.DynamicTilemapLayer#isoCullDistances
* @type {Phaser.Math.Vector2}
* @since 3.23.PR_svipal
* @since 3.23.0
*/
this.isoCullDistances = new Vector2(0, 0);
this.isoCullDistances = new Vector2(1, 1);
/**
* The total number of tiles drawn by the renderer in the last frame.
@ -108448,7 +108468,7 @@ var Utils = __webpack_require__(9);
*
* Use a Static Tilemap Layer instead of a Dynamic Tilemap Layer when you don't need tile manipulation features.
*
* @class StaticTilemapLayers
* @class StaticTilemapLayer
* @extends Phaser.GameObjects.GameObject
* @memberof Phaser.Tilemaps
* @constructor
@ -109549,8 +109569,7 @@ var StaticTilemapLayer = new Class({
*/
hasTileAtWorldXY: function (worldX, worldY, camera)
{
return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera);
return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, this.layer);
},
/**
@ -109746,14 +109765,13 @@ var StaticTilemapLayer = new Class({
},
/**
* Converts from tile X and Y coordinates (tile units) to world X coordinates (pixels), factoring in the
* Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the
* layers position, scale and scroll.
*
* @method Phaser.Tilemaps.StaticTilemapLayer#tileToWorldX
* @since 3.0.0
*
* @param {integer} tileX - The X coordinate, in tile coordinates.
* @param {integer} tileY - The Y coordinate, in tile coordinates.
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the world values from the tile index.
*
* @return {number}
@ -109764,14 +109782,13 @@ var StaticTilemapLayer = new Class({
},
/**
* Converts from tile X and Y coordinates (tile units) to world Y coordinates (pixels), factoring in the
* Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the
* layers position, scale and scroll.
*
* @method Phaser.Tilemaps.StaticTilemapLayer#tileToWorldY
* @since 3.0.0
*
* @param {integer} tileY - The Y coordinate, in tile coordinates.
* @param {integer} tileY - The Y coordinate, in tile coordinates.
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the world values from the tile index.
*
* @return {number}
@ -175555,7 +175572,6 @@ var SnapCeil = __webpack_require__(326);
*/
var CullTiles = function (layer, camera, outputArray, renderOrder)
{
if (outputArray === undefined) { outputArray = []; }
if (renderOrder === undefined) { renderOrder = 0; }
@ -175579,11 +175595,11 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
var drawTop = 0;
var drawBottom = mapHeight;
// we define it earlier for it to make sense in scope
// we define the isometric culling function as a dummy early on for it to make sense in scope
var inIsoBounds = function () { return true; };
if (!tilemapLayer.skipCull && tilemapLayer.scrollFactorX === 1 && tilemapLayer.scrollFactorY === 1)
{
if (layer.orientation === 'orthogonal')
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
{
// Camera world view bounds, snapped for scaled tile size
// Cull Padding values are given in tiles, not pixels
@ -175596,6 +175612,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
drawLeft = Math.max(0, boundsLeft);
drawRight = Math.min(mapWidth, boundsRight);
drawTop = Math.max(0, boundsTop);
drawBottom = Math.min(mapHeight, boundsBottom);
}
else if (layer.orientation === 'isometric')
@ -175604,6 +175621,8 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
{
var cullDistances = tilemapLayer.isoCullDistances;
var pos = tilemapLayer.tileToWorldXY(x,y,undefined,camera);
// we always subtract 1/2 of the tile's height/width to make the culling distance start from the center of the tiles.
return pos.x > camera.worldView.x + tilemapLayer.scaleX * layer.tileWidth * (- cullDistances.x - 1 / 2)
&& pos.x < camera.worldView.right + tilemapLayer.scaleX * layer.tileWidth * (cullDistances.x - 1 / 2)
&& pos.y > camera.worldView.y + tilemapLayer.scaleY * layer.tileHeight * (- cullDistances.y - 1 / 2)
@ -175616,7 +175635,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
var tile;
if (layer.orientation === 'orthogonal')
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
{
if (renderOrder === 0)
@ -177415,7 +177434,7 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, src, interpolationPer
var frameWidth = 0;
var frameHeight = 0;
if (src.layer.orientation === 'isometric')
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered')
{
// 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;
@ -177433,7 +177452,6 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, src, interpolationPer
var tw = frameWidth * 0.5;
var th = frameHeight * 0.5;
var tint = getTint(tile.tint, alpha * tile.alpha);
pipeline.batchTexture(
@ -177559,7 +177577,7 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
var width = tile.width;
var height = tile.width;
if (src.layer.orientation === 'isometric')
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered')
{
// we use the tileset width and height because in isometric maps the tileset's height is often different from the tilemap's.
width = tileset.tileWidth;
@ -177735,6 +177753,7 @@ module.exports = StaticTilemapLayerWebGLRenderer;
var StaticTilemapLayerCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
src.cull(camera);
var renderTiles = src.culledTiles;
var tileCount = renderTiles.length;
@ -177870,6 +177889,7 @@ GameObjectCreator.register('tilemap', function (config)
{
// Defaults are applied in ParseToTilemap
var c = (config !== undefined) ? config : {};
return ParseToTilemap(
this.scene,
c.key,

File diff suppressed because one or more lines are too long

98
dist/phaser.js vendored
View file

@ -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')
else if (orientation === 'isometric' || orientation === 'staggered')
{
var tileWidth = layer.baseTileWidth;
@ -13869,6 +13869,8 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
tileWidth *= tilemapLayer.scaleX;
}
if (orientation === 'isometric')
{
point.x = snapToFloor
? Math.floor((worldX / (tileWidth / 2) + worldY / (tileHeight / 2)) / 2)
: ((worldX / (tileWidth / 2) + worldY / (tileHeight / 2)) / 2);
@ -13877,8 +13879,27 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
? Math.floor((worldY / (tileHeight / 2) - worldX / (tileWidth / 2)) / 2)
: ((worldY / (tileHeight / 2) - worldX / (tileWidth / 2)) / 2);
}
if (orientation === 'orthogonal')
{
point.x = snapToFloor
? Math.floor(worldX / tileWidth)
: worldX / tileWidth;
point.y = snapToFloor
? Math.floor(worldY / tileHeight)
: worldY / tileHeight;
}
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 / tileWidth) - (point.y % 2))
: (worldX / tileWidth) - (point.y % 2);
}
}
return point;
};
@ -13928,7 +13949,6 @@ var Rectangle = __webpack_require__(439);
* support multiple tileset sizes within one map, but they are still placed at intervals of the
* base tile height.
*/
var Tile = new Class({
Mixins: [
@ -14004,7 +14024,7 @@ var Tile = new Class({
* @type {integer}
* @since 3.0.0
*/
this.baseWidth = (baseWidth !== undefined && !baseWidth.isNaN()) ? baseWidth : width;
this.baseWidth = (baseWidth !== undefined) ? baseWidth : width;
/**
* The map's base height of a tile in pixels. Tiled maps support multiple tileset sizes
@ -14014,7 +14034,7 @@ var Tile = new Class({
* @type {integer}
* @since 3.0.0
*/
this.baseHeight = (baseHeight !== undefined && !baseWidth.isNaN()) ? baseHeight : height;
this.baseHeight = (baseHeight !== undefined) ? baseHeight : height;
/**
* The x coordinate of the top left of this tile in pixels. This is relative to the top left
@ -14167,7 +14187,6 @@ var Tile = new Class({
* @since 3.0.0
*/
this.physics = {};
},
/**
@ -14608,7 +14627,6 @@ var Tile = new Class({
this.pixelX = this.x * this.baseWidth;
this.pixelY = this.y * this.baseHeight;
// console.log("orthopix "+this.pixelX+","+this.pixelY)
}
else if (this.layer.orientation === 'isometric')
{
@ -14617,11 +14635,12 @@ var Tile = new Class({
this.pixelX = (this.x - this.y) * this.baseWidth * 0.5;
this.pixelY = (this.x + this.y) * this.baseHeight * 0.5;
// console.log("isopix from",this.x, this.y,"to", this.pixelX+","+this.pixelY)
}
else
else if (this.layer.orientation === 'staggered')
{
// console.warn("this map orientation is is.layer.orientation)
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
this.pixelY = this.y * (this.baseHeight / 2);
}
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);
@ -22101,7 +22120,6 @@ var LayerData = new Class({
*/
this.orientation = GetFastValue(config, 'orientation', 'orthogonal');
/**
* The width in pixels of the entire layer.
*
@ -22200,8 +22218,6 @@ var LayerData = new Class({
* @since 3.0.0
*/
this.tilemapLayer = GetFastValue(config, 'tilemapLayer', null);
}
});
@ -29705,9 +29721,7 @@ var GetTileAt = function (tileX, tileY, nonNull, layer)
else
{
return tile;
}
}
else
{
@ -51573,7 +51587,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')
else if (orientation === 'isometric' || orientation === 'staggered')
{
var layerWorldX = 0;
@ -51589,9 +51603,18 @@ var TileToWorldXY = function (tileX, tileY, point, camera, layer)
}
if (orientation === 'isometric')
{
point.x = layerWorldX + (tileX - tileY) * (tileWidth / 2);
point.y = layerWorldY + (tileX + tileY) * (tileHeight / 2);
}
else if (orientation === 'staggered')
{
// todo
point.x = layerWorldX + tileX * tileWidth + tileY % 2 * (tileWidth / 2);
point.y = layerWorldY + tileY * (tileHeight / 2);
}
}
@ -51644,7 +51667,6 @@ var PutTileAt = function (tile, tileX, tileY, recalculateFaces, layer)
if (tile instanceof Tile)
{
if (layer.data[tileY][tileX] === null)
{
layer.data[tileY][tileX] = new Tile(layer, tile.index, tileX, tileY, layer.tileWidth, layer.tileHeight);
@ -51656,7 +51678,6 @@ var PutTileAt = function (tile, tileX, tileY, recalculateFaces, layer)
var index = tile;
if (layer.data[tileY][tileX] === null)
{
layer.data[tileY][tileX] = new Tile(layer, index, tileX, tileY, layer.tileWidth, layer.tileHeight);
}
else
@ -106003,6 +106024,7 @@ module.exports = rbush;
var TileIntersectsBody = function (tileWorldRect, body)
{
// Currently, all bodies are treated as rectangles when colliding with a Tile.
return !(
body.right <= tileWorldRect.left ||
body.bottom <= tileWorldRect.top ||
@ -107299,7 +107321,6 @@ var TileToWorldX = function (tileX, camera, layer)
tileWidth *= tilemapLayer.scaleX;
}
if (orientation === 'orthogonal')
{
return layerWorldX + tileX * tileWidth;
@ -107800,14 +107821,13 @@ var AssignTileProperties = __webpack_require__(489);
*/
var ParseJSONTiled = function (name, json, insertNull)
{
if (json.orientation === 'isometric')
if (json.orientation === 'isometric' || json.orientation === 'staggered')
{
console.warn('isometric map types are WIP in this version of Phaser');
}
else if (json.orientation !== 'orthogonal')
{
console.warn('Only orthogonal map types are supported in this version of Phaser');
console.warn('Only orthogonal and standard isometric map types are supported in this version of Phaser');
return null;
}
@ -111909,9 +111929,9 @@ var DynamicTilemapLayer = new Class({
*
* @name Phaser.Tilemaps.DynamicTilemapLayer#isoCullDistances
* @type {Phaser.Math.Vector2}
* @since 3.23.PR_svipal
* @since 3.23.0
*/
this.isoCullDistances = new Vector2(0, 0);
this.isoCullDistances = new Vector2(1, 1);
/**
* The total number of tiles drawn by the renderer in the last frame.
@ -113114,7 +113134,7 @@ var Utils = __webpack_require__(9);
*
* Use a Static Tilemap Layer instead of a Dynamic Tilemap Layer when you don't need tile manipulation features.
*
* @class StaticTilemapLayers
* @class StaticTilemapLayer
* @extends Phaser.GameObjects.GameObject
* @memberof Phaser.Tilemaps
* @constructor
@ -114215,8 +114235,7 @@ var StaticTilemapLayer = new Class({
*/
hasTileAtWorldXY: function (worldX, worldY, camera)
{
return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera);
return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, this.layer);
},
/**
@ -114412,14 +114431,13 @@ var StaticTilemapLayer = new Class({
},
/**
* Converts from tile X and Y coordinates (tile units) to world X coordinates (pixels), factoring in the
* Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the
* layers position, scale and scroll.
*
* @method Phaser.Tilemaps.StaticTilemapLayer#tileToWorldX
* @since 3.0.0
*
* @param {integer} tileX - The X coordinate, in tile coordinates.
* @param {integer} tileY - The Y coordinate, in tile coordinates.
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the world values from the tile index.
*
* @return {number}
@ -114430,14 +114448,13 @@ var StaticTilemapLayer = new Class({
},
/**
* Converts from tile X and Y coordinates (tile units) to world Y coordinates (pixels), factoring in the
* Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the
* layers position, scale and scroll.
*
* @method Phaser.Tilemaps.StaticTilemapLayer#tileToWorldY
* @since 3.0.0
*
* @param {integer} tileY - The Y coordinate, in tile coordinates.
* @param {integer} tileY - The Y coordinate, in tile coordinates.
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the world values from the tile index.
*
* @return {number}
@ -183283,7 +183300,6 @@ var SnapCeil = __webpack_require__(326);
*/
var CullTiles = function (layer, camera, outputArray, renderOrder)
{
if (outputArray === undefined) { outputArray = []; }
if (renderOrder === undefined) { renderOrder = 0; }
@ -183307,11 +183323,11 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
var drawTop = 0;
var drawBottom = mapHeight;
// we define it earlier for it to make sense in scope
// we define the isometric culling function as a dummy early on for it to make sense in scope
var inIsoBounds = function () { return true; };
if (!tilemapLayer.skipCull && tilemapLayer.scrollFactorX === 1 && tilemapLayer.scrollFactorY === 1)
{
if (layer.orientation === 'orthogonal')
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
{
// Camera world view bounds, snapped for scaled tile size
// Cull Padding values are given in tiles, not pixels
@ -183324,6 +183340,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
drawLeft = Math.max(0, boundsLeft);
drawRight = Math.min(mapWidth, boundsRight);
drawTop = Math.max(0, boundsTop);
drawBottom = Math.min(mapHeight, boundsBottom);
}
else if (layer.orientation === 'isometric')
@ -183332,6 +183349,8 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
{
var cullDistances = tilemapLayer.isoCullDistances;
var pos = tilemapLayer.tileToWorldXY(x,y,undefined,camera);
// we always subtract 1/2 of the tile's height/width to make the culling distance start from the center of the tiles.
return pos.x > camera.worldView.x + tilemapLayer.scaleX * layer.tileWidth * (- cullDistances.x - 1 / 2)
&& pos.x < camera.worldView.right + tilemapLayer.scaleX * layer.tileWidth * (cullDistances.x - 1 / 2)
&& pos.y > camera.worldView.y + tilemapLayer.scaleY * layer.tileHeight * (- cullDistances.y - 1 / 2)
@ -183344,7 +183363,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
var tile;
if (layer.orientation === 'orthogonal')
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
{
if (renderOrder === 0)
@ -185143,7 +185162,7 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, src, interpolationPer
var frameWidth = 0;
var frameHeight = 0;
if (src.layer.orientation === 'isometric')
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered')
{
// 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;
@ -185161,7 +185180,6 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, src, interpolationPer
var tw = frameWidth * 0.5;
var th = frameHeight * 0.5;
var tint = getTint(tile.tint, alpha * tile.alpha);
pipeline.batchTexture(
@ -185287,7 +185305,7 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
var width = tile.width;
var height = tile.width;
if (src.layer.orientation === 'isometric')
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered')
{
// we use the tileset width and height because in isometric maps the tileset's height is often different from the tilemap's.
width = tileset.tileWidth;
@ -185463,6 +185481,7 @@ module.exports = StaticTilemapLayerWebGLRenderer;
var StaticTilemapLayerCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
src.cull(camera);
var renderTiles = src.culledTiles;
var tileCount = renderTiles.length;
@ -185598,6 +185617,7 @@ GameObjectCreator.register('tilemap', function (config)
{
// Defaults are applied in ParseToTilemap
var c = (config !== undefined) ? config : {};
return ParseToTilemap(
this.scene,
c.key,

2
dist/phaser.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -22,6 +22,8 @@
"buildfb": "webpack --config config/webpack.fb.config.js",
"watchfb": "webpack --config config/webpack.fb.config.js --watch",
"dist": "webpack --config config/webpack.dist.config.js",
"distT": "webpack --config config/webpack.dist.config.js && npm run toT",
"toT": "@powershell Copy-Item ./dist/phaser.min.js ../phasertest/phaser.min.js",
"distfb": "webpack --config config/webpack.fb.dist.config.js",
"distfull": "npm run dist && npm run distfb",
"plugin.cam3d": "webpack --config plugins/camera3d/webpack.config.js",

View file

@ -714,7 +714,6 @@ var Tile = new Class({
this.pixelX = this.x * this.baseWidth;
this.pixelY = this.y * this.baseHeight;
// console.log("orthopix "+this.pixelX+","+this.pixelY)
}
else if (this.layer.orientation === 'isometric')
{
@ -723,11 +722,12 @@ var Tile = new Class({
this.pixelX = (this.x - this.y) * this.baseWidth * 0.5;
this.pixelY = (this.x + this.y) * this.baseHeight * 0.5;
// console.log("isopix from",this.x, this.y,"to", this.pixelX+","+this.pixelY)
}
else
else if (this.layer.orientation === 'staggered')
{
// console.warn("this map orientation is is.layer.orientation)
this.pixelX = this.x * this.baseWidth + this.y % 2 * (this.baseWidth / 2);
this.pixelY = this.y * (this.baseHeight / 2);
}
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);

View file

@ -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')
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
{
// Camera world view bounds, snapped for scaled tile size
// Cull Padding values are given in tiles, not pixels
@ -62,6 +62,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
drawLeft = Math.max(0, boundsLeft);
drawRight = Math.min(mapWidth, boundsRight);
drawTop = Math.max(0, boundsTop);
drawBottom = Math.min(mapHeight, boundsBottom);
}
else if (layer.orientation === 'isometric')
@ -84,7 +85,7 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
var tile;
if (layer.orientation === 'orthogonal')
if (layer.orientation === 'orthogonal' || layer.orientation === 'staggered')
{
if (renderOrder === 0)

View file

@ -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')
else if (orientation === 'isometric' || orientation === 'staggered')
{
var layerWorldX = 0;
@ -59,9 +59,18 @@ var TileToWorldXY = function (tileX, tileY, point, camera, layer)
}
if (orientation === 'isometric')
{
point.x = layerWorldX + (tileX - tileY) * (tileWidth / 2);
point.y = layerWorldY + (tileX + tileY) * (tileHeight / 2);
}
else if (orientation === 'staggered')
{
// todo
point.x = layerWorldX + tileX * tileWidth + tileY % 2 * (tileWidth / 2);
point.y = layerWorldY + tileY * (tileHeight / 2);
}
}

View file

@ -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')
else if (orientation === 'isometric' || orientation === 'staggered')
{
var tileWidth = layer.baseTileWidth;
@ -62,6 +62,8 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
tileWidth *= tilemapLayer.scaleX;
}
if (orientation === 'isometric')
{
point.x = snapToFloor
? Math.floor((worldX / (tileWidth / 2) + worldY / (tileHeight / 2)) / 2)
: ((worldX / (tileWidth / 2) + worldY / (tileHeight / 2)) / 2);
@ -70,8 +72,27 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
? Math.floor((worldY / (tileHeight / 2) - worldX / (tileWidth / 2)) / 2)
: ((worldY / (tileHeight / 2) - worldX / (tileWidth / 2)) / 2);
}
if (orientation === 'orthogonal')
{
point.x = snapToFloor
? Math.floor(worldX / tileWidth)
: worldX / tileWidth;
point.y = snapToFloor
? Math.floor(worldY / tileHeight)
: worldY / tileHeight;
}
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 / tileWidth) - (point.y % 2))
: (worldX / tileWidth) - (point.y % 2);
}
}
return point;
};

View file

@ -92,7 +92,7 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
var width = tile.width;
var height = tile.width;
if (src.layer.orientation === 'isometric')
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered')
{
// we use the tileset width and height because in isometric maps the tileset's height is often different from the tilemap's.
width = tileset.tileWidth;

View file

@ -78,7 +78,7 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, src, interpolationPer
var frameWidth = 0;
var frameHeight = 0;
if (src.layer.orientation === 'isometric')
if (src.layer.orientation === 'isometric' || src.layer.orientation === 'staggered')
{
// 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;

View file

@ -32,7 +32,7 @@ var AssignTileProperties = require('./AssignTileProperties');
*/
var ParseJSONTiled = function (name, json, insertNull)
{
if (json.orientation === 'isometric')
if (json.orientation === 'isometric' || json.orientation === 'staggered')
{
console.warn('isometric map types are WIP in this version of Phaser');
}