updated dynamic layer and tilemap

This commit is contained in:
No 2020-01-17 16:15:59 +01:00
parent f17aef0abf
commit 1a88ff95ba
4 changed files with 14 additions and 26 deletions

View file

@ -2345,7 +2345,7 @@ var Tilemap = new Class({
if (layer === null) { return null; }
return TilemapComponents.TileToWorldX(tileX, camera, layer);
return TilemapComponents.TileToWorldX(tileX, camera, layer, this.orientation);
},
/**
@ -2370,7 +2370,7 @@ var Tilemap = new Class({
if (layer === null) { return null; }
return TilemapComponents.TileToWorldY(tileX, camera, layer);
return TilemapComponents.TileToWorldY(tileX, camera, layer, this.orientation);
},
/**
@ -2397,7 +2397,7 @@ var Tilemap = new Class({
if (layer === null) { return null; }
return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, layer);
return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, layer, this.orientation);
},
/**
@ -2468,7 +2468,7 @@ var Tilemap = new Class({
if (layer === null) { return null; }
return TilemapComponents.WorldToTileX(worldX, snapToFloor, camera, layer);
return TilemapComponents.WorldToTileX(worldX, snapToFloor, camera, layer, this.orientation);
},
/**
@ -2493,7 +2493,7 @@ var Tilemap = new Class({
if (layer === null) { return null; }
return TilemapComponents.WorldToTileY(worldY, snapToFloor, camera, layer);
return TilemapComponents.WorldToTileY(worldY, snapToFloor, camera, layer,this.orientation);
},
/**
@ -2521,7 +2521,7 @@ var Tilemap = new Class({
if (layer === null) { return null; }
return TilemapComponents.WorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer);
return TilemapComponents.WorldToTileXY(worldX, worldY, snapToFloor, point, camera, layer, this.orientation);
},
/**

View file

@ -28,9 +28,7 @@ var TileToWorldY = function (tileY, camera, layer)
if (tilemapLayer)
{
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
layerWorldY = (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
tileHeight *= tilemapLayer.scaleY;
}

View file

@ -27,19 +27,11 @@ var WorldToTileX = function (worldX, snapToFloor, camera, layer, orientation)
if (snapToFloor === undefined) { snapToFloor = true; }
var tileWidth = layer.baseTileWidth;
var tileHeight = layer.baseTileHeight;
var tilemapLayer = layer.tilemapLayer;
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 vertical scroll
worldY = worldY - (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
tileHeight *= tilemapLayer.scaleY;
// 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));
@ -52,10 +44,8 @@ var WorldToTileX = function (worldX, snapToFloor, camera, layer, orientation)
? Math.floor(worldX / tileWidth)
: worldX / tileWidth;
} else if (orientation === "isometric") {
return snapToFloor
? Math.floor((worldX/(tileWidth/2) + worldY/(tileHeight/2))/2)
: ((worldX/(tileWidth/2) + worldY/(tileHeight/2))/2);
console.warn('With isometric map types you have to use the WorldToTileXY function.');
return null
}
};

View file

@ -1178,7 +1178,7 @@ var DynamicTilemapLayer = new Class({
*/
tileToWorldX: function (tileX, camera)
{
return TilemapComponents.TileToWorldX(tileX, camera, this.layer);
return TilemapComponents.TileToWorldX(tileX, camera, this.layer, this.tilemap.orientation);
},
/**
@ -1195,7 +1195,7 @@ var DynamicTilemapLayer = new Class({
*/
tileToWorldY: function (tileY, camera)
{
return TilemapComponents.TileToWorldY(tileY, camera, this.layer);
return TilemapComponents.TileToWorldY(tileY, camera, this.layer, this.tilemap.orientation);
},
/**
@ -1215,7 +1215,7 @@ var DynamicTilemapLayer = new Class({
*/
tileToWorldXY: function (tileX, tileY, point, camera)
{
return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, this.layer);
return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, this.layer, this.tilemap.orientation);
},
/**
@ -1268,7 +1268,7 @@ var DynamicTilemapLayer = new Class({
*/
worldToTileX: function (worldX, snapToFloor, camera)
{
return TilemapComponents.WorldToTileX(worldX, snapToFloor, camera, this.layer);
return TilemapComponents.WorldToTileX(worldX, snapToFloor, camera, this.layer, this.tilemap.orientation);
},
/**
@ -1286,7 +1286,7 @@ var DynamicTilemapLayer = new Class({
*/
worldToTileY: function (worldY, snapToFloor, camera)
{
return TilemapComponents.WorldToTileY(worldY, snapToFloor, camera, this.layer);
return TilemapComponents.WorldToTileY(worldY, snapToFloor, camera, this.layer, this.tilemap.orientation);
},
/**
@ -1307,7 +1307,7 @@ var DynamicTilemapLayer = new Class({
*/
worldToTileXY: function (worldX, worldY, snapToFloor, point, camera)
{
return TilemapComponents.WorldToTileXY(worldX, worldY, snapToFloor, point, camera, this.layer);
return TilemapComponents.WorldToTileXY(worldX, worldY, snapToFloor, point, camera, this.layer, this.tilemap.orientation);
}
});