mirror of
https://github.com/photonstorm/phaser
synced 2024-12-23 11:33:28 +00:00
linted everything
This commit is contained in:
parent
786834be5e
commit
dc330aaf4a
27 changed files with 156 additions and 128 deletions
|
@ -66,7 +66,7 @@ var ParseToTilemap = function (scene, key, tileWidth, tileHeight, width, height,
|
||||||
|
|
||||||
if (mapData === null)
|
if (mapData === null)
|
||||||
{
|
{
|
||||||
console.log("null mapdata")
|
console.log('null mapdata');
|
||||||
mapData = new MapData({
|
mapData = new MapData({
|
||||||
tileWidth: tileWidth,
|
tileWidth: tileWidth,
|
||||||
tileHeight: tileHeight,
|
tileHeight: tileHeight,
|
||||||
|
|
|
@ -708,22 +708,28 @@ var Tile = new Class({
|
||||||
*/
|
*/
|
||||||
updatePixelXY: function ()
|
updatePixelXY: function ()
|
||||||
{
|
{
|
||||||
if (this.layer.orientation === "orthogonal") {
|
if (this.layer.orientation === 'orthogonal')
|
||||||
|
{
|
||||||
// In orthogonal mode, Tiled places tiles on a grid of baseWidth x baseHeight. The origin for a tile is the
|
// In orthogonal mode, Tiled places tiles on a grid of baseWidth x baseHeight. The origin for a tile is the
|
||||||
// bottom left, while the Phaser renderer assumes the origin is the top left. The y
|
// bottom left, while the Phaser renderer assumes the origin is the top left. The y
|
||||||
// coordinate needs to be adjusted by the difference.
|
// coordinate needs to be adjusted by the difference.
|
||||||
this.pixelX = this.x * this.baseWidth;
|
this.pixelX = this.x * this.baseWidth;
|
||||||
this.pixelY = this.y * this.baseHeight;
|
this.pixelY = this.y * this.baseHeight;
|
||||||
|
|
||||||
// console.log("orthopix "+this.pixelX+","+this.pixelY)
|
// console.log("orthopix "+this.pixelX+","+this.pixelY)
|
||||||
} else if (this.layer.orientation === "isometric" ) {
|
}
|
||||||
|
else if (this.layer.orientation === 'isometric')
|
||||||
|
{
|
||||||
// reminder : for the tilemap to be centered we have to move the image to the right with the camera !
|
// reminder : for the tilemap to be centered we have to move the image to the right with the camera !
|
||||||
// this is crucial for wordtotile, tiletoworld to work.
|
// this is crucial for wordtotile, tiletoworld to work.
|
||||||
this.pixelX = (this.x - this.y) * this.baseWidth * 0.5;
|
this.pixelX = (this.x - this.y) * this.baseWidth * 0.5;
|
||||||
this.pixelY = (this.x + this.y) * this.baseHeight * 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)
|
// console.log("isopix from",this.x, this.y,"to", this.pixelX+","+this.pixelY)
|
||||||
} else {
|
}
|
||||||
// console.warn("this map orientation is not supported in this version of phaser")
|
else
|
||||||
// console.log("tile orientation 3: "+this.layer.orientation)
|
{
|
||||||
|
// console.warn("this map orientation is is.layer.orientation)
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);
|
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);
|
||||||
|
|
|
@ -135,7 +135,6 @@ var Tilemap = new Class({
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
this.orientation = mapData.orientation;
|
this.orientation = mapData.orientation;
|
||||||
console.log("map orientation :" + this.orientation)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The render (draw) order of the map data (as specified in Tiled), usually 'right-down'.
|
* The render (draw) order of the map data (as specified in Tiled), usually 'right-down'.
|
||||||
|
@ -505,7 +504,6 @@ var Tilemap = new Class({
|
||||||
height: height,
|
height: height,
|
||||||
orientation: this.orientation
|
orientation: this.orientation
|
||||||
});
|
});
|
||||||
console.log("tm orientation : ",layerData.orientation)
|
|
||||||
|
|
||||||
var row;
|
var row;
|
||||||
|
|
||||||
|
@ -2348,7 +2346,7 @@ var Tilemap = new Class({
|
||||||
|
|
||||||
if (layer === null) { return null; }
|
if (layer === null) { return null; }
|
||||||
|
|
||||||
return TilemapComponents.TileToWorldX(tileX, camera, layer, this.orientation);
|
return TilemapComponents.TileToWorldX(tileX, camera, layer);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2373,7 +2371,7 @@ var Tilemap = new Class({
|
||||||
|
|
||||||
if (layer === null) { return null; }
|
if (layer === null) { return null; }
|
||||||
|
|
||||||
return TilemapComponents.TileToWorldY(tileX, camera, layer, this.orientation);
|
return TilemapComponents.TileToWorldY(tileX, camera, layer);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2400,7 +2398,7 @@ var Tilemap = new Class({
|
||||||
|
|
||||||
if (layer === null) { return null; }
|
if (layer === null) { return null; }
|
||||||
|
|
||||||
return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, layer, this.orientation);
|
return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, layer);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2471,7 +2469,7 @@ var Tilemap = new Class({
|
||||||
|
|
||||||
if (layer === null) { return null; }
|
if (layer === null) { return null; }
|
||||||
|
|
||||||
return TilemapComponents.WorldToTileX(worldX, snapToFloor, camera, layer, this.orientation);
|
return TilemapComponents.WorldToTileX(worldX, snapToFloor, camera, layer);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2496,7 +2494,7 @@ var Tilemap = new Class({
|
||||||
|
|
||||||
if (layer === null) { return null; }
|
if (layer === null) { return null; }
|
||||||
|
|
||||||
return TilemapComponents.WorldToTileY(worldY, snapToFloor, camera, layer,this.orientation);
|
return TilemapComponents.WorldToTileY(worldY, snapToFloor, camera, layer);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2524,7 +2522,7 @@ var Tilemap = new Class({
|
||||||
|
|
||||||
if (layer === null) { return null; }
|
if (layer === null) { return null; }
|
||||||
|
|
||||||
return TilemapComponents.WorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer, this.orientation);
|
return TilemapComponents.WorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,7 +24,6 @@ GameObjectCreator.register('tilemap', function (config)
|
||||||
{
|
{
|
||||||
// Defaults are applied in ParseToTilemap
|
// Defaults are applied in ParseToTilemap
|
||||||
var c = (config !== undefined) ? config : {};
|
var c = (config !== undefined) ? config : {};
|
||||||
console.log("TC tilemap")
|
|
||||||
return ParseToTilemap(
|
return ParseToTilemap(
|
||||||
this.scene,
|
this.scene,
|
||||||
c.key,
|
c.key,
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var TileToWorldX = require('./TileToWorldX');
|
var TileToWorldXY = require('./TileToWorldXY');
|
||||||
var TileToWorldY = require('./TileToWorldY');
|
|
||||||
var GetTilesWithin = require('./GetTilesWithin');
|
var GetTilesWithin = require('./GetTilesWithin');
|
||||||
var ReplaceByIndex = require('./ReplaceByIndex');
|
var ReplaceByIndex = require('./ReplaceByIndex');
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ var CreateFromTiles = function (indexes, replacements, spriteConfig, scene, came
|
||||||
|
|
||||||
if (indexes.indexOf(tile.index) !== -1)
|
if (indexes.indexOf(tile.index) !== -1)
|
||||||
{
|
{
|
||||||
var point = TileToWorldXY(tile.x,tile.y, camera, layer)
|
var point = TileToWorldXY(tile.x,tile.y, camera, layer);
|
||||||
spriteConfig.x = point.x;
|
spriteConfig.x = point.x;
|
||||||
spriteConfig.y = point.y;
|
spriteConfig.y = point.y;
|
||||||
var sprite = scene.make.sprite(spriteConfig);
|
var sprite = scene.make.sprite(spriteConfig);
|
||||||
|
|
|
@ -45,9 +45,13 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
||||||
var drawRight = mapWidth;
|
var drawRight = mapWidth;
|
||||||
var drawTop = 0;
|
var drawTop = 0;
|
||||||
var drawBottom = mapHeight;
|
var drawBottom = mapHeight;
|
||||||
var inIsoBounds = function (x,y) { return true;}
|
|
||||||
if (!tilemapLayer.skipCull && tilemapLayer.scrollFactorX === 1 && tilemapLayer.scrollFactorY === 1) {
|
// we define it earlier for it to make sense in scope
|
||||||
if (layer.orientation == "orthogonal") {
|
var inIsoBounds = function () { return true; };
|
||||||
|
if (!tilemapLayer.skipCull && tilemapLayer.scrollFactorX === 1 && tilemapLayer.scrollFactorY === 1)
|
||||||
|
{
|
||||||
|
if (layer.orientation === 'orthogonal')
|
||||||
|
{
|
||||||
// Camera world view bounds, snapped for scaled tile size
|
// Camera world view bounds, snapped for scaled tile size
|
||||||
// Cull Padding values are given in tiles, not pixels
|
// Cull Padding values are given in tiles, not pixels
|
||||||
|
|
||||||
|
@ -60,11 +64,14 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
||||||
drawRight = Math.min(mapWidth, boundsRight);
|
drawRight = Math.min(mapWidth, boundsRight);
|
||||||
drawTop = Math.max(0, boundsTop);
|
drawTop = Math.max(0, boundsTop);
|
||||||
drawBottom = Math.min(mapHeight, boundsBottom);
|
drawBottom = Math.min(mapHeight, boundsBottom);
|
||||||
} else if (layer.orientation == "isometric") {
|
|
||||||
inIsoBounds = function (x,y){
|
|
||||||
var pos = tilemapLayer.tileToWorldXY(x,y,undefined,camera)
|
|
||||||
return (pos.x > camera.worldView.x && pos.x < camera.worldView.right) && (pos.y > camera.worldView.y && pos.y < camera.worldView.bottom)
|
|
||||||
}
|
}
|
||||||
|
else if (layer.orientation === 'isometric')
|
||||||
|
{
|
||||||
|
inIsoBounds = function (x,y)
|
||||||
|
{
|
||||||
|
var pos = tilemapLayer.tileToWorldXY(x,y,undefined,camera);
|
||||||
|
return (pos.x > camera.worldView.x && pos.x < camera.worldView.right) && (pos.y > camera.worldView.y && pos.y < camera.worldView.bottom);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var x;
|
var x;
|
||||||
|
@ -72,7 +79,8 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
||||||
var tile;
|
var tile;
|
||||||
|
|
||||||
|
|
||||||
if (layer.orientation == "orthogonal") {
|
if (layer.orientation === 'orthogonal')
|
||||||
|
{
|
||||||
|
|
||||||
if (renderOrder === 0)
|
if (renderOrder === 0)
|
||||||
{
|
{
|
||||||
|
@ -150,7 +158,9 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (layer.orientation == "isometric") {
|
}
|
||||||
|
else if (layer.orientation === 'isometric')
|
||||||
|
{
|
||||||
if (renderOrder === 0)
|
if (renderOrder === 0)
|
||||||
{
|
{
|
||||||
// right-down
|
// right-down
|
||||||
|
@ -159,7 +169,8 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
||||||
{
|
{
|
||||||
for (x = drawLeft; mapData[y] && x < drawRight; x++)
|
for (x = drawLeft; mapData[y] && x < drawRight; x++)
|
||||||
{
|
{
|
||||||
if (inIsoBounds(x,y)) {
|
if (inIsoBounds(x,y))
|
||||||
|
{
|
||||||
tile = mapData[y][x];
|
tile = mapData[y][x];
|
||||||
|
|
||||||
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
|
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
|
||||||
|
@ -181,7 +192,8 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
||||||
{
|
{
|
||||||
for (x = drawRight; mapData[y] && x >= drawLeft; x--)
|
for (x = drawRight; mapData[y] && x >= drawLeft; x--)
|
||||||
{
|
{
|
||||||
if (inIsoBounds(x,y)) {
|
if (inIsoBounds(x,y))
|
||||||
|
{
|
||||||
tile = mapData[y][x];
|
tile = mapData[y][x];
|
||||||
|
|
||||||
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
|
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
|
||||||
|
@ -202,7 +214,8 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
||||||
{
|
{
|
||||||
for (x = drawLeft; mapData[y] && x < drawRight; x++)
|
for (x = drawLeft; mapData[y] && x < drawRight; x++)
|
||||||
{
|
{
|
||||||
if (inIsoBounds(x,y)) {
|
if (inIsoBounds(x,y))
|
||||||
|
{
|
||||||
tile = mapData[y][x];
|
tile = mapData[y][x];
|
||||||
|
|
||||||
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
|
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
|
||||||
|
@ -223,7 +236,8 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
||||||
{
|
{
|
||||||
for (x = drawRight; mapData[y] && x >= drawLeft; x--)
|
for (x = drawRight; mapData[y] && x >= drawLeft; x--)
|
||||||
{
|
{
|
||||||
if (inIsoBounds(x,y)) {
|
if (inIsoBounds(x,y))
|
||||||
|
{
|
||||||
tile = mapData[y][x];
|
tile = mapData[y][x];
|
||||||
|
|
||||||
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
|
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var GetTileAt = require('./GetTileAt');
|
var GetTileAt = require('./GetTileAt');
|
||||||
var WorldToTileX = require('./WorldToTileX');
|
var WorldToTileXY = require('./WorldToTileXY');
|
||||||
var WorldToTileY = require('./WorldToTileY');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a tile at the given world coordinates from the given layer.
|
* Gets a tile at the given world coordinates from the given layer.
|
||||||
|
@ -27,8 +26,8 @@ var WorldToTileY = require('./WorldToTileY');
|
||||||
var GetTileAtWorldXY = function (worldX, worldY, nonNull, camera, layer)
|
var GetTileAtWorldXY = function (worldX, worldY, nonNull, camera, layer)
|
||||||
{
|
{
|
||||||
var point = WorldToTileXY(worldX, worldY, true, camera, layer);
|
var point = WorldToTileXY(worldX, worldY, true, camera, layer);
|
||||||
var tileX = point.x
|
var tileX = point.x;
|
||||||
var tileY = point.y
|
var tileY = point.y;
|
||||||
return GetTileAt(tileX, tileY, nonNull, layer);
|
return GetTileAt(tileX, tileY, nonNull, layer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,8 @@ var Geom = require('../../geom/');
|
||||||
var GetTilesWithin = require('./GetTilesWithin');
|
var GetTilesWithin = require('./GetTilesWithin');
|
||||||
var Intersects = require('../../geom/intersects/');
|
var Intersects = require('../../geom/intersects/');
|
||||||
var NOOP = require('../../utils/NOOP');
|
var NOOP = require('../../utils/NOOP');
|
||||||
var TileToWorldX = require('./TileToWorldX');
|
var TileToWorldXY = require('./TileToWorldXY');
|
||||||
var TileToWorldY = require('./TileToWorldY');
|
var WorldToTileXY = require('./WorldToTileXY');
|
||||||
var WorldToTileX = require('./WorldToTileX');
|
|
||||||
var WorldToTileY = require('./WorldToTileY');
|
|
||||||
|
|
||||||
var TriangleToRectangle = function (triangle, rect)
|
var TriangleToRectangle = function (triangle, rect)
|
||||||
{
|
{
|
||||||
|
@ -41,7 +39,6 @@ var TriangleToRectangle = function (triangle, rect)
|
||||||
*/
|
*/
|
||||||
var GetTilesWithinShape = function (shape, filteringOptions, camera, layer)
|
var GetTilesWithinShape = function (shape, filteringOptions, camera, layer)
|
||||||
{
|
{
|
||||||
var orientation = layer.orientation;
|
|
||||||
if (shape === undefined) { return []; }
|
if (shape === undefined) { return []; }
|
||||||
|
|
||||||
// intersectTest is a function with parameters: shape, rect
|
// intersectTest is a function with parameters: shape, rect
|
||||||
|
@ -52,12 +49,12 @@ var GetTilesWithinShape = function (shape, filteringOptions, camera, layer)
|
||||||
else if (shape instanceof Geom.Line) { intersectTest = Intersects.LineToRectangle; }
|
else if (shape instanceof Geom.Line) { intersectTest = Intersects.LineToRectangle; }
|
||||||
|
|
||||||
// Top left corner of the shapes's bounding box, rounded down to include partial tiles
|
// Top left corner of the shapes's bounding box, rounded down to include partial tiles
|
||||||
var pointStart = WorldToTileXY(shape.left, shape.top, true, camera, layer, orientation);
|
var pointStart = WorldToTileXY(shape.left, shape.top, true, camera, layer);
|
||||||
var xStart = pointStart.x;
|
var xStart = pointStart.x;
|
||||||
var yStart = pointStart.y;
|
var yStart = pointStart.y;
|
||||||
|
|
||||||
// Bottom right corner of the shapes's bounding box, rounded up to include partial tiles
|
// Bottom right corner of the shapes's bounding box, rounded up to include partial tiles
|
||||||
var pointEnd = WorldToTileXY(shape.right, shape.bottom, true, camera, layer, orientation);
|
var pointEnd = WorldToTileXY(shape.right, shape.bottom, true, camera, layer);
|
||||||
var xEnd = Math.ceil(pointEnd.x);
|
var xEnd = Math.ceil(pointEnd.x);
|
||||||
var yEnd = Math.ceil(pointEnd.y);
|
var yEnd = Math.ceil(pointEnd.y);
|
||||||
|
|
||||||
|
@ -80,8 +77,9 @@ var GetTilesWithinShape = function (shape, filteringOptions, camera, layer)
|
||||||
for (var i = 0; i < tiles.length; i++)
|
for (var i = 0; i < tiles.length; i++)
|
||||||
{
|
{
|
||||||
var tile = tiles[i];
|
var tile = tiles[i];
|
||||||
tileRect.x = TileToWorldX(tile.x, camera, layer);
|
var point = TileToWorldXY(tile.x, tile.y, camera, layer);
|
||||||
tileRect.y = TileToWorldY(tile.y, camera, layer);
|
tileRect.x = point.x;
|
||||||
|
tileRect.y = point.y;
|
||||||
if (intersectTest(shape, tileRect))
|
if (intersectTest(shape, tileRect))
|
||||||
{
|
{
|
||||||
results.push(tile);
|
results.push(tile);
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var GetTilesWithin = require('./GetTilesWithin');
|
var GetTilesWithin = require('./GetTilesWithin');
|
||||||
var WorldToTileX = require('./WorldToTileX');
|
|
||||||
var WorldToTileY = require('./WorldToTileY');
|
|
||||||
var WorldToTileXY = require('./WorldToTileXY');
|
var WorldToTileXY = require('./WorldToTileXY');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +29,8 @@ var WorldToTileXY = require('./WorldToTileXY');
|
||||||
*/
|
*/
|
||||||
var GetTilesWithinWorldXY = function (worldX, worldY, width, height, filteringOptions, camera, layer)
|
var GetTilesWithinWorldXY = function (worldX, worldY, width, height, filteringOptions, camera, layer)
|
||||||
{
|
{
|
||||||
var orientation = layer.orientation
|
var orientation = layer.orientation;
|
||||||
|
|
||||||
// Top left corner of the rect, rounded down to include partial tiles
|
// Top left corner of the rect, rounded down to include partial tiles
|
||||||
var pointStart = WorldToTileXY(worldX, worldY, true, camera, layer, orientation);
|
var pointStart = WorldToTileXY(worldX, worldY, true, camera, layer, orientation);
|
||||||
var xStart = pointStart.x;
|
var xStart = pointStart.x;
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var HasTileAt = require('./HasTileAt');
|
var HasTileAt = require('./HasTileAt');
|
||||||
var WorldToTileX = require('./WorldToTileX');
|
var WorldToTileXY = require('./WorldToTileXY');
|
||||||
var WorldToTileY = require('./WorldToTileY');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if there is a tile at the given location (in world coordinates) in the given layer. Returns
|
* Checks if there is a tile at the given location (in world coordinates) in the given layer. Returns
|
||||||
|
|
|
@ -57,6 +57,7 @@ var PutTileAt = function (tile, tileX, tileY, recalculateFaces, layer)
|
||||||
layer.data[tileY][tileX].index = index;
|
layer.data[tileY][tileX].index = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updating colliding flag on the new tile
|
// Updating colliding flag on the new tile
|
||||||
var newTile = layer.data[tileY][tileX];
|
var newTile = layer.data[tileY][tileX];
|
||||||
var collides = layer.collideIndexes.indexOf(newTile.index) !== -1;
|
var collides = layer.collideIndexes.indexOf(newTile.index) !== -1;
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var PutTileAt = require('./PutTileAt');
|
var PutTileAt = require('./PutTileAt');
|
||||||
var WorldToTileX = require('./WorldToTileX');
|
var WorldToTileXY = require('./WorldToTileXY');
|
||||||
var WorldToTileY = require('./WorldToTileY');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puts a tile at the given world coordinates (pixels) in the specified layer. You can pass in either
|
* Puts a tile at the given world coordinates (pixels) in the specified layer. You can pass in either
|
||||||
|
@ -29,10 +28,9 @@ var WorldToTileY = require('./WorldToTileY');
|
||||||
*/
|
*/
|
||||||
var PutTileAtWorldXY = function (tile, worldX, worldY, recalculateFaces, camera, layer)
|
var PutTileAtWorldXY = function (tile, worldX, worldY, recalculateFaces, camera, layer)
|
||||||
{
|
{
|
||||||
var orientation = layer.orientation
|
|
||||||
var point = WorldToTileXY(worldX, worldY, true, camera, layer);
|
var point = WorldToTileXY(worldX, worldY, true, camera, layer);
|
||||||
var tileX = point.x
|
var tileX = point.x;
|
||||||
var tileY = point.y
|
var tileY = point.y;
|
||||||
return PutTileAt(tile, tileX, tileY, recalculateFaces, layer);
|
return PutTileAt(tile, tileX, tileY, recalculateFaces, layer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var RemoveTileAt = require('./RemoveTileAt');
|
var RemoveTileAt = require('./RemoveTileAt');
|
||||||
var WorldToTileX = require('./WorldToTileX');
|
var WorldToTileXY = require('./WorldToTileXY');
|
||||||
var WorldToTileY = require('./WorldToTileY');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the tile at the given world coordinates in the specified layer and updates the layer's
|
* Removes the tile at the given world coordinates in the specified layer and updates the layer's
|
||||||
|
@ -27,10 +26,9 @@ var WorldToTileY = require('./WorldToTileY');
|
||||||
*/
|
*/
|
||||||
var RemoveTileAtWorldXY = function (worldX, worldY, replaceWithNull, recalculateFaces, camera, layer)
|
var RemoveTileAtWorldXY = function (worldX, worldY, replaceWithNull, recalculateFaces, camera, layer)
|
||||||
{
|
{
|
||||||
var orientation = layer.orientation
|
|
||||||
var point = WorldToTileXY(worldX, worldY, true, camera, layer);
|
var point = WorldToTileXY(worldX, worldY, true, camera, layer);
|
||||||
var tileX = point.x
|
var tileX = point.x;
|
||||||
var tileY = point.y
|
var tileY = point.y;
|
||||||
return RemoveTileAt(tileX, tileY, replaceWithNull, recalculateFaces, layer);
|
return RemoveTileAt(tileX, tileY, replaceWithNull, recalculateFaces, layer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,12 @@ var TileToWorldX = function (tileX, camera, layer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (orientation === "orthogonal") {
|
if (orientation === 'orthogonal')
|
||||||
|
{
|
||||||
return layerWorldX + tileX * tileWidth;
|
return layerWorldX + tileX * tileWidth;
|
||||||
} else if (orientation === "isometric") {
|
}
|
||||||
|
else if (orientation === 'isometric')
|
||||||
|
{
|
||||||
// Not Best Solution ?
|
// Not Best Solution ?
|
||||||
console.warn('With isometric map types you have to use the TileToWorldXY function.');
|
console.warn('With isometric map types you have to use the TileToWorldXY function.');
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -38,10 +38,13 @@ var TileToWorldXY = function (tileX, tileY, point, camera, layer)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (orientation === "orthogonal") {
|
if (orientation === 'orthogonal')
|
||||||
|
{
|
||||||
point.x = TileToWorldX(tileX, camera, layer, orientation);
|
point.x = TileToWorldX(tileX, camera, layer, orientation);
|
||||||
point.y = TileToWorldY(tileY, camera, layer, orientation);
|
point.y = TileToWorldY(tileY, camera, layer, orientation);
|
||||||
} else if (orientation === "isometric") {
|
}
|
||||||
|
else if (orientation === 'isometric')
|
||||||
|
{
|
||||||
|
|
||||||
var layerWorldX = 0;
|
var layerWorldX = 0;
|
||||||
var layerWorldY = 0;
|
var layerWorldY = 0;
|
||||||
|
|
|
@ -32,9 +32,12 @@ var TileToWorldY = function (tileY, camera, layer)
|
||||||
tileHeight *= tilemapLayer.scaleY;
|
tileHeight *= tilemapLayer.scaleY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (orientation === "orthogonal") {
|
if (orientation === 'orthogonal')
|
||||||
|
{
|
||||||
return layerWorldY + tileY * tileHeight;
|
return layerWorldY + tileY * tileHeight;
|
||||||
} else if (orientation === "isometric") {
|
}
|
||||||
|
else if (orientation === 'isometric')
|
||||||
|
{
|
||||||
// Not Best Solution ?
|
// Not Best Solution ?
|
||||||
console.warn('With isometric map types you have to use the TileToWorldXY function.');
|
console.warn('With isometric map types you have to use the TileToWorldXY function.');
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -31,6 +31,7 @@ var WorldToTileX = function (worldX, snapToFloor, camera, layer)
|
||||||
if (tilemapLayer)
|
if (tilemapLayer)
|
||||||
{
|
{
|
||||||
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
|
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
|
||||||
|
|
||||||
// Find the world position relative to the static or dynamic layer's top left origin,
|
// Find the world position relative to the static or dynamic layer's top left origin,
|
||||||
// factoring in the camera's horizontal scroll
|
// factoring in the camera's horizontal scroll
|
||||||
worldX = worldX - (tilemapLayer.x + camera.scrollX * (1 - tilemapLayer.scrollFactorX));
|
worldX = worldX - (tilemapLayer.x + camera.scrollX * (1 - tilemapLayer.scrollFactorX));
|
||||||
|
@ -38,13 +39,16 @@ var WorldToTileX = function (worldX, snapToFloor, camera, layer)
|
||||||
tileWidth *= tilemapLayer.scaleX;
|
tileWidth *= tilemapLayer.scaleX;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (orientation === "orthogonal") {
|
if (orientation === 'orthogonal')
|
||||||
|
{
|
||||||
return snapToFloor
|
return snapToFloor
|
||||||
? Math.floor(worldX / tileWidth)
|
? Math.floor(worldX / tileWidth)
|
||||||
: worldX / tileWidth;
|
: worldX / tileWidth;
|
||||||
} else if (orientation === "isometric") {
|
}
|
||||||
|
else if (orientation === 'isometric')
|
||||||
|
{
|
||||||
console.warn('With isometric map types you have to use the WorldToTileXY function.');
|
console.warn('With isometric map types you have to use the WorldToTileXY function.');
|
||||||
return null
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,10 +31,13 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
|
||||||
var orientation = layer.orientation;
|
var orientation = layer.orientation;
|
||||||
if (point === undefined) { point = new Vector2(0, 0); }
|
if (point === undefined) { point = new Vector2(0, 0); }
|
||||||
|
|
||||||
if (orientation === "orthogonal") {
|
if (orientation === 'orthogonal')
|
||||||
|
{
|
||||||
point.x = WorldToTileX(worldX, snapToFloor, camera, layer, orientation);
|
point.x = WorldToTileX(worldX, snapToFloor, camera, layer, orientation);
|
||||||
point.y = WorldToTileY(worldY, snapToFloor, camera, layer, orientation);
|
point.y = WorldToTileY(worldY, snapToFloor, camera, layer, orientation);
|
||||||
} else if (orientation === 'isometric') {
|
}
|
||||||
|
else if (orientation === 'isometric')
|
||||||
|
{
|
||||||
|
|
||||||
var tileWidth = layer.baseTileWidth;
|
var tileWidth = layer.baseTileWidth;
|
||||||
var tileHeight = layer.baseTileHeight;
|
var tileHeight = layer.baseTileHeight;
|
||||||
|
@ -48,6 +51,7 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
|
||||||
// factoring in the camera's vertical scroll
|
// factoring in the camera's vertical scroll
|
||||||
// console.log(1,worldY)
|
// console.log(1,worldY)
|
||||||
worldY = worldY - (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
|
worldY = worldY - (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
|
||||||
|
|
||||||
// console.log(worldY)
|
// console.log(worldY)
|
||||||
tileHeight *= tilemapLayer.scaleY;
|
tileHeight *= tilemapLayer.scaleY;
|
||||||
|
|
||||||
|
|
|
@ -38,13 +38,16 @@ var WorldToTileY = function (worldY, snapToFloor, camera, layer)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (orientation === "orthogonal") {
|
if (orientation === 'orthogonal')
|
||||||
|
{
|
||||||
return snapToFloor
|
return snapToFloor
|
||||||
? Math.floor(worldY / tileHeight)
|
? Math.floor(worldY / tileHeight)
|
||||||
: worldY / tileHeight;
|
: worldY / tileHeight;
|
||||||
} else if (orientation === "isometric") {
|
}
|
||||||
|
else if (orientation === 'isometric')
|
||||||
|
{
|
||||||
console.warn('With isometric map types you have to use the WorldToTileXY function.');
|
console.warn('With isometric map types you have to use the WorldToTileXY function.');
|
||||||
return null
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -249,8 +249,8 @@ var DynamicTilemapLayer = new Class({
|
||||||
|
|
||||||
this.initPipeline('TextureTintPipeline');
|
this.initPipeline('TextureTintPipeline');
|
||||||
|
|
||||||
console.log("layer sizes")
|
console.log('layer sizes');
|
||||||
console.log(this.layer.tileWidth,this.layer.tileHeight)
|
console.log(this.layer.tileWidth,this.layer.tileHeight);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -92,14 +92,15 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
|
||||||
var width = tile.width;
|
var width = tile.width;
|
||||||
var height = tile.width;
|
var height = tile.width;
|
||||||
|
|
||||||
if (src.layer.orientation === "isometric") {
|
if (src.layer.orientation === 'isometric')
|
||||||
// here we use the tileset width and height to fix problems with isometric map types
|
{
|
||||||
|
// 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;
|
width = tileset.tileWidth;
|
||||||
width = tileset.tileHeight;
|
width = tileset.tileHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
halfWidth = width / 2;
|
var halfWidth = width / 2;
|
||||||
halfHeight = height / 2;
|
var halfHeight = height / 2;
|
||||||
|
|
||||||
ctx.save();
|
ctx.save();
|
||||||
|
|
||||||
|
|
|
@ -74,28 +74,27 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, src, interpolationPer
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (src.layer.orientation === "isometric") {
|
|
||||||
// here we use the tileset width and height to fix problems with isometric map types
|
|
||||||
|
|
||||||
var frameWidth = tileset.tileWidth;
|
var frameWidth = 0;
|
||||||
var frameHeight = tileset.tileHeight;
|
var frameHeight = 0;
|
||||||
|
|
||||||
var frameX = tileTexCoords.x;
|
if (src.layer.orientation === 'isometric')
|
||||||
var frameY = tileTexCoords.y;
|
{
|
||||||
|
// we use the tileset width and height because in isometric maps the tileset's height is often different from the tilemap's.
|
||||||
var tw = tileset.tileWidth * 0.5;
|
frameWidth = tileset.tileWidth;
|
||||||
var th = tileset.tileHeight * 0.5;
|
frameHeight = tileset.tileHeight;
|
||||||
} else {
|
}
|
||||||
var frameWidth = tile.width;
|
else
|
||||||
var frameHeight = tile.height;
|
{
|
||||||
|
frameWidth = tile.width;
|
||||||
var frameX = tileTexCoords.x;
|
frameHeight = tile.height;
|
||||||
var frameY = tileTexCoords.y;
|
|
||||||
|
|
||||||
var tw = tile.width * 0.5;
|
|
||||||
var th = tile.height * 0.5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var frameX = tileTexCoords.x;
|
||||||
|
var frameY = tileTexCoords.y;
|
||||||
|
|
||||||
|
var tw = frameWidth * 0.5;
|
||||||
|
var th = frameHeight * 0.5;
|
||||||
|
|
||||||
|
|
||||||
var tint = getTint(tile.tint, alpha * tile.alpha);
|
var tint = getTint(tile.tint, alpha * tile.alpha);
|
||||||
|
|
|
@ -116,7 +116,7 @@ var LayerData = new Class({
|
||||||
* @type {string}
|
* @type {string}
|
||||||
* @since 3.22.PR_svipal
|
* @since 3.22.PR_svipal
|
||||||
*/
|
*/
|
||||||
this.orientation = GetFastValue(config, 'orientation', "orthogonal");
|
this.orientation = GetFastValue(config, 'orientation', 'orthogonal');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -117,7 +117,8 @@ var MapData = new Class({
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
*/
|
*/
|
||||||
this.orientation = GetFastValue(config, 'orientation', 'orthogonal');
|
this.orientation = GetFastValue(config, 'orientation', 'orthogonal');
|
||||||
console.log("map data orientation : " + this.orientation)
|
console.log('map data orientation : ' + this.orientation);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the draw order of tilemap. Default is right-down
|
* Determines the draw order of tilemap. Default is right-down
|
||||||
*
|
*
|
||||||
|
|
|
@ -34,7 +34,6 @@ var Parse2DArray = function (name, data, tileWidth, tileHeight, insertNull)
|
||||||
tileWidth: tileWidth,
|
tileWidth: tileWidth,
|
||||||
tileHeight: tileHeight
|
tileHeight: tileHeight
|
||||||
});
|
});
|
||||||
console.log("parsing 2D array")
|
|
||||||
var mapData = new MapData({
|
var mapData = new MapData({
|
||||||
name: name,
|
name: name,
|
||||||
tileWidth: tileWidth,
|
tileWidth: tileWidth,
|
||||||
|
|
|
@ -32,11 +32,13 @@ var AssignTileProperties = require('./AssignTileProperties');
|
||||||
*/
|
*/
|
||||||
var ParseJSONTiled = function (name, json, insertNull)
|
var ParseJSONTiled = function (name, json, insertNull)
|
||||||
{
|
{
|
||||||
if (json.orientation == 'isometric')
|
if (json.orientation === 'isometric')
|
||||||
{
|
{
|
||||||
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 !== 'orthogonal') {
|
}
|
||||||
|
else if (json.orientation !== 'orthogonal')
|
||||||
|
{
|
||||||
console.warn('Only orthogonal map types are supported in this version of Phaser');
|
console.warn('Only orthogonal map types are supported in this version of Phaser');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,6 @@ var ParseTileLayers = function (json, insertNull)
|
||||||
orientation: json.orientation
|
orientation: json.orientation
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("layerdata orientation", layerData.orientation)
|
|
||||||
|
|
||||||
for (var c = 0; c < curl.height; c++)
|
for (var c = 0; c < curl.height; c++)
|
||||||
{
|
{
|
||||||
|
@ -206,7 +205,6 @@ var ParseTileLayers = function (json, insertNull)
|
||||||
properties: GetFastValue(curl, 'properties', {}),
|
properties: GetFastValue(curl, 'properties', {}),
|
||||||
orientation: json.orientation
|
orientation: json.orientation
|
||||||
});
|
});
|
||||||
console.log("layerdata orientation", layerData.orientation)
|
|
||||||
var row = [];
|
var row = [];
|
||||||
|
|
||||||
// Loop through the data field in the JSON.
|
// Loop through the data field in the JSON.
|
||||||
|
|
Loading…
Reference in a new issue