mirror of
https://github.com/photonstorm/phaser
synced 2024-12-23 03:23:42 +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)
|
||||
{
|
||||
console.log("null mapdata")
|
||||
console.log('null mapdata');
|
||||
mapData = new MapData({
|
||||
tileWidth: tileWidth,
|
||||
tileHeight: tileHeight,
|
||||
|
|
|
@ -47,7 +47,7 @@ var Tile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function Tile (layer, index, x, y, width, height, baseWidth, baseHeight )
|
||||
function Tile (layer, index, x, y, width, height, baseWidth, baseHeight)
|
||||
{
|
||||
/**
|
||||
* The LayerData in the Tilemap data that this tile belongs to.
|
||||
|
@ -708,22 +708,28 @@ var Tile = new Class({
|
|||
*/
|
||||
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
|
||||
// bottom left, while the Phaser renderer assumes the origin is the top left. The y
|
||||
// coordinate needs to be adjusted by the difference.
|
||||
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" ) {
|
||||
}
|
||||
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 !
|
||||
// this is crucial for wordtotile, tiletoworld to work.
|
||||
this.pixelX = (this.x - this.y) * this.baseWidth *0.5;
|
||||
this.pixelY = (this.x + this.y) * this.baseHeight *0.5;
|
||||
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 {
|
||||
// console.warn("this map orientation is not supported in this version of phaser")
|
||||
// console.log("tile orientation 3: "+this.layer.orientation)
|
||||
}
|
||||
else
|
||||
{
|
||||
// console.warn("this map orientation is is.layer.orientation)
|
||||
}
|
||||
|
||||
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);
|
||||
|
|
|
@ -135,7 +135,6 @@ var Tilemap = new Class({
|
|||
* @since 3.0.0
|
||||
*/
|
||||
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'.
|
||||
|
@ -505,8 +504,7 @@ var Tilemap = new Class({
|
|||
height: height,
|
||||
orientation: this.orientation
|
||||
});
|
||||
console.log("tm orientation : ",layerData.orientation)
|
||||
|
||||
|
||||
var row;
|
||||
|
||||
for (var tileY = 0; tileY < height; tileY++)
|
||||
|
@ -2348,7 +2346,7 @@ var Tilemap = new Class({
|
|||
|
||||
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; }
|
||||
|
||||
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; }
|
||||
|
||||
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; }
|
||||
|
||||
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; }
|
||||
|
||||
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; }
|
||||
|
||||
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
|
||||
var c = (config !== undefined) ? config : {};
|
||||
console.log("TC tilemap")
|
||||
return ParseToTilemap(
|
||||
this.scene,
|
||||
c.key,
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
var TileToWorldX = require('./TileToWorldX');
|
||||
var TileToWorldY = require('./TileToWorldY');
|
||||
var TileToWorldXY = require('./TileToWorldXY');
|
||||
var GetTilesWithin = require('./GetTilesWithin');
|
||||
var ReplaceByIndex = require('./ReplaceByIndex');
|
||||
|
||||
|
@ -48,7 +47,7 @@ var CreateFromTiles = function (indexes, replacements, spriteConfig, scene, came
|
|||
|
||||
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.y = point.y;
|
||||
var sprite = scene.make.sprite(spriteConfig);
|
||||
|
|
|
@ -45,34 +45,42 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
|||
var drawRight = mapWidth;
|
||||
var drawTop = 0;
|
||||
var drawBottom = mapHeight;
|
||||
var inIsoBounds = function (x,y) { return true;}
|
||||
if (!tilemapLayer.skipCull && tilemapLayer.scrollFactorX === 1 && tilemapLayer.scrollFactorY === 1) {
|
||||
if (layer.orientation == "orthogonal") {
|
||||
|
||||
// we define it earlier 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')
|
||||
{
|
||||
// Camera world view bounds, snapped for scaled tile size
|
||||
// Cull Padding values are given in tiles, not pixels
|
||||
|
||||
var boundsLeft = SnapFloor(camera.worldView.x - tilemapLayer.x, tileW, 0, true) - tilemapLayer.cullPaddingX;
|
||||
var boundsRight = SnapCeil(camera.worldView.right - tilemapLayer.x, tileW, 0, true) + tilemapLayer.cullPaddingX;
|
||||
var boundsTop = SnapFloor(camera.worldView.y - tilemapLayer.y, tileH, 0, true) - tilemapLayer.cullPaddingY;
|
||||
var boundsLeft = SnapFloor(camera.worldView.x - tilemapLayer.x, tileW, 0, true) - tilemapLayer.cullPaddingX;
|
||||
var boundsRight = SnapCeil(camera.worldView.right - tilemapLayer.x, tileW, 0, true) + tilemapLayer.cullPaddingX;
|
||||
var boundsTop = SnapFloor(camera.worldView.y - tilemapLayer.y, tileH, 0, true) - tilemapLayer.cullPaddingY;
|
||||
var boundsBottom = SnapCeil(camera.worldView.bottom - tilemapLayer.y, tileH, 0, true) + tilemapLayer.cullPaddingY;
|
||||
|
||||
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") {
|
||||
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 y;
|
||||
var tile;
|
||||
|
||||
|
||||
if (layer.orientation == "orthogonal") {
|
||||
if (layer.orientation === 'orthogonal')
|
||||
{
|
||||
|
||||
if (renderOrder === 0)
|
||||
{
|
||||
|
@ -150,8 +158,10 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (layer.orientation == "isometric") {
|
||||
if (renderOrder === 0)
|
||||
}
|
||||
else if (layer.orientation === 'isometric')
|
||||
{
|
||||
if (renderOrder === 0)
|
||||
{
|
||||
// right-down
|
||||
|
||||
|
@ -159,7 +169,8 @@ var CullTiles = function (layer, camera, outputArray, renderOrder)
|
|||
{
|
||||
for (x = drawLeft; mapData[y] && x < drawRight; x++)
|
||||
{
|
||||
if (inIsoBounds(x,y)) {
|
||||
if (inIsoBounds(x,y))
|
||||
{
|
||||
tile = mapData[y][x];
|
||||
|
||||
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--)
|
||||
{
|
||||
if (inIsoBounds(x,y)) {
|
||||
if (inIsoBounds(x,y))
|
||||
{
|
||||
tile = mapData[y][x];
|
||||
|
||||
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++)
|
||||
{
|
||||
if (inIsoBounds(x,y)) {
|
||||
if (inIsoBounds(x,y))
|
||||
{
|
||||
tile = mapData[y][x];
|
||||
|
||||
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--)
|
||||
{
|
||||
if (inIsoBounds(x,y)) {
|
||||
if (inIsoBounds(x,y))
|
||||
{
|
||||
tile = mapData[y][x];
|
||||
|
||||
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
*/
|
||||
|
||||
var GetTileAt = require('./GetTileAt');
|
||||
var WorldToTileX = require('./WorldToTileX');
|
||||
var WorldToTileY = require('./WorldToTileY');
|
||||
var WorldToTileXY = require('./WorldToTileXY');
|
||||
|
||||
/**
|
||||
* 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 point = WorldToTileXY(worldX, worldY, true, camera, layer);
|
||||
var tileX = point.x
|
||||
var tileY = point.y
|
||||
var tileX = point.x;
|
||||
var tileY = point.y;
|
||||
return GetTileAt(tileX, tileY, nonNull, layer);
|
||||
};
|
||||
|
||||
|
|
|
@ -8,10 +8,8 @@ var Geom = require('../../geom/');
|
|||
var GetTilesWithin = require('./GetTilesWithin');
|
||||
var Intersects = require('../../geom/intersects/');
|
||||
var NOOP = require('../../utils/NOOP');
|
||||
var TileToWorldX = require('./TileToWorldX');
|
||||
var TileToWorldY = require('./TileToWorldY');
|
||||
var WorldToTileX = require('./WorldToTileX');
|
||||
var WorldToTileY = require('./WorldToTileY');
|
||||
var TileToWorldXY = require('./TileToWorldXY');
|
||||
var WorldToTileXY = require('./WorldToTileXY');
|
||||
|
||||
var TriangleToRectangle = function (triangle, rect)
|
||||
{
|
||||
|
@ -41,7 +39,6 @@ var TriangleToRectangle = function (triangle, rect)
|
|||
*/
|
||||
var GetTilesWithinShape = function (shape, filteringOptions, camera, layer)
|
||||
{
|
||||
var orientation = layer.orientation;
|
||||
if (shape === undefined) { return []; }
|
||||
|
||||
// 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; }
|
||||
|
||||
// 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 yStart = pointStart.y;
|
||||
|
||||
// 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 yEnd = Math.ceil(pointEnd.y);
|
||||
|
||||
|
@ -80,8 +77,9 @@ var GetTilesWithinShape = function (shape, filteringOptions, camera, layer)
|
|||
for (var i = 0; i < tiles.length; i++)
|
||||
{
|
||||
var tile = tiles[i];
|
||||
tileRect.x = TileToWorldX(tile.x, camera, layer);
|
||||
tileRect.y = TileToWorldY(tile.y, camera, layer);
|
||||
var point = TileToWorldXY(tile.x, tile.y, camera, layer);
|
||||
tileRect.x = point.x;
|
||||
tileRect.y = point.y;
|
||||
if (intersectTest(shape, tileRect))
|
||||
{
|
||||
results.push(tile);
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
*/
|
||||
|
||||
var GetTilesWithin = require('./GetTilesWithin');
|
||||
var WorldToTileX = require('./WorldToTileX');
|
||||
var WorldToTileY = require('./WorldToTileY');
|
||||
var WorldToTileXY = require('./WorldToTileXY');
|
||||
|
||||
/**
|
||||
|
@ -31,14 +29,15 @@ var WorldToTileXY = require('./WorldToTileXY');
|
|||
*/
|
||||
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
|
||||
var pointStart = WorldToTileXY(worldX, worldY, true, camera, layer, orientation);
|
||||
var xStart = pointStart.x;
|
||||
var yStart = pointStart.y;
|
||||
|
||||
// Bottom right corner of the rect, rounded up to include partial tiles
|
||||
var pointEnd = WorldToTileXY(worldX+ width, worldY+ height, true, camera, layer, orientation);
|
||||
var pointEnd = WorldToTileXY(worldX + width, worldY + height, true, camera, layer, orientation);
|
||||
var xEnd = Math.ceil(pointEnd.x);
|
||||
var yEnd = Math.ceil(pointEnd.y);
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
*/
|
||||
|
||||
var HasTileAt = require('./HasTileAt');
|
||||
var WorldToTileX = require('./WorldToTileX');
|
||||
var WorldToTileY = require('./WorldToTileY');
|
||||
var WorldToTileXY = require('./WorldToTileXY');
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
// Updating colliding flag on the new tile
|
||||
var newTile = layer.data[tileY][tileX];
|
||||
var collides = layer.collideIndexes.indexOf(newTile.index) !== -1;
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
*/
|
||||
|
||||
var PutTileAt = require('./PutTileAt');
|
||||
var WorldToTileX = require('./WorldToTileX');
|
||||
var WorldToTileY = require('./WorldToTileY');
|
||||
var WorldToTileXY = require('./WorldToTileXY');
|
||||
|
||||
/**
|
||||
* 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 orientation = layer.orientation
|
||||
var point = WorldToTileXY(worldX, worldY, true, camera, layer);
|
||||
var tileX = point.x
|
||||
var tileY = point.y
|
||||
var tileX = point.x;
|
||||
var tileY = point.y;
|
||||
return PutTileAt(tile, tileX, tileY, recalculateFaces, layer);
|
||||
};
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
*/
|
||||
|
||||
var RemoveTileAt = require('./RemoveTileAt');
|
||||
var WorldToTileX = require('./WorldToTileX');
|
||||
var WorldToTileY = require('./WorldToTileY');
|
||||
var WorldToTileXY = require('./WorldToTileXY');
|
||||
|
||||
/**
|
||||
* 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 orientation = layer.orientation
|
||||
var point = WorldToTileXY(worldX, worldY, true, camera, layer);
|
||||
var tileX = point.x
|
||||
var tileY = point.y
|
||||
var tileX = point.x;
|
||||
var tileY = point.y;
|
||||
return RemoveTileAt(tileX, tileY, replaceWithNull, recalculateFaces, layer);
|
||||
};
|
||||
|
||||
|
|
|
@ -35,12 +35,15 @@ var TileToWorldX = function (tileX, camera, layer)
|
|||
}
|
||||
|
||||
|
||||
if (orientation === "orthogonal") {
|
||||
return layerWorldX + tileX * tileWidth;
|
||||
} else if (orientation === "isometric") {
|
||||
if (orientation === 'orthogonal')
|
||||
{
|
||||
return layerWorldX + tileX * tileWidth;
|
||||
}
|
||||
else if (orientation === 'isometric')
|
||||
{
|
||||
// Not Best Solution ?
|
||||
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.y = TileToWorldY(tileY, camera, layer, orientation);
|
||||
} else if (orientation === "isometric") {
|
||||
}
|
||||
else if (orientation === 'isometric')
|
||||
{
|
||||
|
||||
var layerWorldX = 0;
|
||||
var layerWorldY = 0;
|
||||
|
@ -57,8 +60,8 @@ var TileToWorldXY = function (tileX, tileY, point, camera, layer)
|
|||
|
||||
|
||||
|
||||
point.x = layerWorldX + (tileX - tileY) * (tileWidth/2);
|
||||
point.y = layerWorldY + (tileX + tileY) * (tileHeight/2);
|
||||
point.x = layerWorldX + (tileX - tileY) * (tileWidth / 2);
|
||||
point.y = layerWorldY + (tileX + tileY) * (tileHeight / 2);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -32,12 +32,15 @@ var TileToWorldY = function (tileY, camera, layer)
|
|||
tileHeight *= tilemapLayer.scaleY;
|
||||
}
|
||||
|
||||
if (orientation === "orthogonal") {
|
||||
return layerWorldY + tileY * tileHeight;
|
||||
} else if (orientation === "isometric") {
|
||||
if (orientation === 'orthogonal')
|
||||
{
|
||||
return layerWorldY + tileY * tileHeight;
|
||||
}
|
||||
else if (orientation === 'isometric')
|
||||
{
|
||||
// Not Best Solution ?
|
||||
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 (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
|
||||
|
||||
// Find the world position relative to the static or dynamic layer's top left origin,
|
||||
// factoring in the camera's horizontal scroll
|
||||
worldX = worldX - (tilemapLayer.x + camera.scrollX * (1 - tilemapLayer.scrollFactorX));
|
||||
|
@ -38,13 +39,16 @@ var WorldToTileX = function (worldX, snapToFloor, camera, layer)
|
|||
tileWidth *= tilemapLayer.scaleX;
|
||||
}
|
||||
|
||||
if (orientation === "orthogonal") {
|
||||
if (orientation === 'orthogonal')
|
||||
{
|
||||
return snapToFloor
|
||||
? Math.floor(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.');
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -31,10 +31,13 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
|
|||
var orientation = layer.orientation;
|
||||
if (point === undefined) { point = new Vector2(0, 0); }
|
||||
|
||||
if (orientation === "orthogonal") {
|
||||
if (orientation === 'orthogonal')
|
||||
{
|
||||
point.x = WorldToTileX(worldX, 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 tileHeight = layer.baseTileHeight;
|
||||
|
@ -48,6 +51,7 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
|
|||
// factoring in the camera's vertical scroll
|
||||
// console.log(1,worldY)
|
||||
worldY = worldY - (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
|
||||
|
||||
// console.log(worldY)
|
||||
tileHeight *= tilemapLayer.scaleY;
|
||||
|
||||
|
@ -59,12 +63,12 @@ var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
|
|||
}
|
||||
|
||||
point.x = snapToFloor
|
||||
? Math.floor((worldX/(tileWidth/2) + worldY/(tileHeight/2))/2)
|
||||
: ((worldX/(tileWidth/2) + worldY/(tileHeight/2))/2);
|
||||
? Math.floor((worldX / (tileWidth / 2) + worldY / (tileHeight / 2)) / 2)
|
||||
: ((worldX / (tileWidth / 2) + worldY / (tileHeight / 2)) / 2);
|
||||
|
||||
point.y = snapToFloor
|
||||
? Math.floor((worldY/(tileHeight/2) - worldX/(tileWidth/2))/2)
|
||||
: ((worldY/(tileHeight/2) - worldX/(tileWidth/2))/2);
|
||||
point.y = snapToFloor
|
||||
? Math.floor((worldY / (tileHeight / 2) - worldX / (tileWidth / 2)) / 2)
|
||||
: ((worldY / (tileHeight / 2) - worldX / (tileWidth / 2)) / 2);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -38,13 +38,16 @@ var WorldToTileY = function (worldY, snapToFloor, camera, layer)
|
|||
|
||||
}
|
||||
|
||||
if (orientation === "orthogonal") {
|
||||
if (orientation === 'orthogonal')
|
||||
{
|
||||
return snapToFloor
|
||||
? Math.floor(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.');
|
||||
return null
|
||||
return null;
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
@ -249,8 +249,8 @@ var DynamicTilemapLayer = new Class({
|
|||
|
||||
this.initPipeline('TextureTintPipeline');
|
||||
|
||||
console.log("layer sizes")
|
||||
console.log(this.layer.tileWidth,this.layer.tileHeight)
|
||||
console.log('layer sizes');
|
||||
console.log(this.layer.tileWidth,this.layer.tileHeight);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,14 +92,15 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
|
|||
var width = tile.width;
|
||||
var height = tile.width;
|
||||
|
||||
if (src.layer.orientation === "isometric") {
|
||||
// here we use the tileset width and height to fix problems with isometric map types
|
||||
if (src.layer.orientation === 'isometric')
|
||||
{
|
||||
// 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.tileHeight;
|
||||
}
|
||||
|
||||
halfWidth = width / 2;
|
||||
halfHeight = height / 2;
|
||||
var halfWidth = width / 2;
|
||||
var halfHeight = height / 2;
|
||||
|
||||
ctx.save();
|
||||
|
||||
|
|
|
@ -74,28 +74,27 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, src, interpolationPer
|
|||
{
|
||||
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 frameHeight = tileset.tileHeight;
|
||||
|
||||
var frameX = tileTexCoords.x;
|
||||
var frameY = tileTexCoords.y;
|
||||
|
||||
var tw = tileset.tileWidth * 0.5;
|
||||
var th = tileset.tileHeight * 0.5;
|
||||
} else {
|
||||
var frameWidth = tile.width;
|
||||
var frameHeight = tile.height;
|
||||
|
||||
var frameX = tileTexCoords.x;
|
||||
var frameY = tileTexCoords.y;
|
||||
|
||||
var tw = tile.width * 0.5;
|
||||
var th = tile.height * 0.5;
|
||||
|
||||
var frameWidth = 0;
|
||||
var frameHeight = 0;
|
||||
|
||||
if (src.layer.orientation === 'isometric')
|
||||
{
|
||||
// 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;
|
||||
frameHeight = tileset.tileHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
frameWidth = tile.width;
|
||||
frameHeight = tile.height;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -116,7 +116,7 @@ var LayerData = new Class({
|
|||
* @type {string}
|
||||
* @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
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
|
|
@ -34,7 +34,6 @@ var Parse2DArray = function (name, data, tileWidth, tileHeight, insertNull)
|
|||
tileWidth: tileWidth,
|
||||
tileHeight: tileHeight
|
||||
});
|
||||
console.log("parsing 2D array")
|
||||
var mapData = new MapData({
|
||||
name: name,
|
||||
tileWidth: tileWidth,
|
||||
|
|
|
@ -32,11 +32,13 @@ var AssignTileProperties = require('./AssignTileProperties');
|
|||
*/
|
||||
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');
|
||||
|
||||
} else if (json.orientation !== 'orthogonal') {
|
||||
}
|
||||
else if (json.orientation !== 'orthogonal')
|
||||
{
|
||||
console.warn('Only orthogonal map types are supported in this version of Phaser');
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -131,7 +131,6 @@ var ParseTileLayers = function (json, insertNull)
|
|||
orientation: json.orientation
|
||||
});
|
||||
|
||||
console.log("layerdata orientation", layerData.orientation)
|
||||
|
||||
for (var c = 0; c < curl.height; c++)
|
||||
{
|
||||
|
@ -206,7 +205,6 @@ var ParseTileLayers = function (json, insertNull)
|
|||
properties: GetFastValue(curl, 'properties', {}),
|
||||
orientation: json.orientation
|
||||
});
|
||||
console.log("layerdata orientation", layerData.orientation)
|
||||
var row = [];
|
||||
|
||||
// Loop through the data field in the JSON.
|
||||
|
|
Loading…
Reference in a new issue