fixed problems with putting tiles from null tiles

This commit is contained in:
Svipal 2020-02-05 18:37:40 +01:00
parent a8b60cf946
commit aaf512b9cd
10 changed files with 65 additions and 64 deletions

View file

@ -12226,7 +12226,6 @@ var Tile = new Class({
function Tile (layer, index, x, y, width, height, baseWidth, baseHeight )
{
console.log(this)
/**
* The LayerData in the Tilemap data that this tile belongs to.
*
@ -12886,7 +12885,7 @@ 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.
@ -12894,14 +12893,14 @@ var Tile = new Class({
this.pixelY = this.y * this.baseHeight;
// console.log("orthopix "+this.pixelX+","+this.pixelY)
} else if (this.layer.orientation === "isometric" ) {
// for the image 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.pixelX = (this.x - this.y) * this.baseWidth *0.5;
this.pixelY = (this.x + this.y) * this.baseHeight *0.5;
// console.log("isopix "+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")
console.log("tile orientation 3: "+this.layer.orientation)
// console.warn("this map orientation is not supported in this version of phaser")
// console.log("tile orientation 3: "+this.layer.orientation)
}
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);
@ -47399,9 +47398,10 @@ 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, tile.width, tile.height);
layer.data[tileY][tileX] = new Tile(layer, tile.index, tileX, tileY, layer.tileWidth, layer.tileHeight);
}
layer.data[tileY][tileX].copy(tile);
}
@ -47410,6 +47410,7 @@ 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
@ -47417,7 +47418,6 @@ 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;
@ -47428,7 +47428,7 @@ var PutTileAt = function (tile, tileX, tileY, recalculateFaces, layer)
{
CalculateFacesAt(tileX, tileY, layer);
}
return newTile;
};
@ -107144,6 +107144,9 @@ var DynamicTilemapLayer = new Class({
this.setSize(tilemap.tileWidth * this.layer.width, tilemap.tileHeight * this.layer.height);
this.initPipeline('TextureTintPipeline');
console.log("layer sizes")
console.log(this.layer.tileWidth,this.layer.tileHeight)
},
/**
@ -177320,7 +177323,6 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
var renderTiles = src.culledTiles;
var tileCount = renderTiles.length;
if (tileCount === 0)
{
return;
@ -177370,8 +177372,8 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
for (var i = 0; i < tileCount; i++)
{
var tile = renderTiles[i];
var tile = renderTiles[i];
var tileset = gidMap[tile.index];
if (!tileset)
@ -177380,21 +177382,20 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
}
var image = tileset.image.getSourceImage();
var tileTexCoords = tileset.getTileTextureCoordinates(tile.index);
var tileTexCoords = tileset.getTileTextureCoordinates(tile.index);
if (tileTexCoords)
{
var width = 0;
var height = 0;
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
width = tileset.tileWidth;
width = tileset.tileHeight;
} else {
width = tile.width;
height = tile.width
}
halfWidth = width / 2;
halfHeight = height / 2;
@ -177413,17 +177414,18 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
}
ctx.globalAlpha = alpha * tile.alpha;
ctx.drawImage(
image,
tileTexCoords.x, tileTexCoords.y,
width, height,
tileset.tileWidth, tileset.tileHeight,
-halfWidth, -halfHeight,
width, height
);
ctx.restore();
}
}
ctx.restore();

File diff suppressed because one or more lines are too long

40
dist/phaser.js vendored
View file

@ -14150,7 +14150,6 @@ var Tile = new Class({
function Tile (layer, index, x, y, width, height, baseWidth, baseHeight )
{
console.log(this)
/**
* The LayerData in the Tilemap data that this tile belongs to.
*
@ -14810,7 +14809,7 @@ 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.
@ -14818,14 +14817,14 @@ var Tile = new Class({
this.pixelY = this.y * this.baseHeight;
// console.log("orthopix "+this.pixelX+","+this.pixelY)
} else if (this.layer.orientation === "isometric" ) {
// for the image 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.pixelX = (this.x - this.y) * this.baseWidth *0.5;
this.pixelY = (this.x + this.y) * this.baseHeight *0.5;
// console.log("isopix "+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")
console.log("tile orientation 3: "+this.layer.orientation)
// console.warn("this map orientation is not supported in this version of phaser")
// console.log("tile orientation 3: "+this.layer.orientation)
}
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);
@ -51689,9 +51688,10 @@ 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, tile.width, tile.height);
layer.data[tileY][tileX] = new Tile(layer, tile.index, tileX, tileY, layer.tileWidth, layer.tileHeight);
}
layer.data[tileY][tileX].copy(tile);
}
@ -51700,6 +51700,7 @@ 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
@ -51707,7 +51708,6 @@ 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;
@ -51718,7 +51718,7 @@ var PutTileAt = function (tile, tileX, tileY, recalculateFaces, layer)
{
CalculateFacesAt(tileX, tileY, layer);
}
return newTile;
};
@ -111955,6 +111955,9 @@ var DynamicTilemapLayer = new Class({
this.setSize(tilemap.tileWidth * this.layer.width, tilemap.tileHeight * this.layer.height);
this.initPipeline('TextureTintPipeline');
console.log("layer sizes")
console.log(this.layer.tileWidth,this.layer.tileHeight)
},
/**
@ -185246,7 +185249,6 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
var renderTiles = src.culledTiles;
var tileCount = renderTiles.length;
if (tileCount === 0)
{
return;
@ -185296,8 +185298,8 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
for (var i = 0; i < tileCount; i++)
{
var tile = renderTiles[i];
var tile = renderTiles[i];
var tileset = gidMap[tile.index];
if (!tileset)
@ -185306,21 +185308,20 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
}
var image = tileset.image.getSourceImage();
var tileTexCoords = tileset.getTileTextureCoordinates(tile.index);
var tileTexCoords = tileset.getTileTextureCoordinates(tile.index);
if (tileTexCoords)
{
var width = 0;
var height = 0;
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
width = tileset.tileWidth;
width = tileset.tileHeight;
} else {
width = tile.width;
height = tile.width
}
halfWidth = width / 2;
halfHeight = height / 2;
@ -185339,17 +185340,18 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
}
ctx.globalAlpha = alpha * tile.alpha;
ctx.drawImage(
image,
tileTexCoords.x, tileTexCoords.y,
width, height,
tileset.tileWidth, tileset.tileHeight,
-halfWidth, -halfHeight,
width, height
);
ctx.restore();
}
}
ctx.restore();

2
dist/phaser.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -73,8 +73,6 @@ var ParseToTilemap = function (scene, key, tileWidth, tileHeight, width, height,
width: width,
height: height
});
} else {
console.log(mapData.orientation)
}
return new Tilemap(scene, mapData);

View file

@ -49,7 +49,6 @@ var Tile = new Class({
function Tile (layer, index, x, y, width, height, baseWidth, baseHeight )
{
console.log(this)
/**
* The LayerData in the Tilemap data that this tile belongs to.
*
@ -709,7 +708,7 @@ 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.
@ -717,14 +716,14 @@ var Tile = new Class({
this.pixelY = this.y * this.baseHeight;
// console.log("orthopix "+this.pixelX+","+this.pixelY)
} else if (this.layer.orientation === "isometric" ) {
// for the image 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.pixelX = (this.x - this.y) * this.baseWidth *0.5;
this.pixelY = (this.x + this.y) * this.baseHeight *0.5;
// console.log("isopix "+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")
console.log("tile orientation 3: "+this.layer.orientation)
// console.warn("this map orientation is not supported in this version of phaser")
// console.log("tile orientation 3: "+this.layer.orientation)
}
// this.pixelY = this.y * this.baseHeight - (this.height - this.baseHeight);

View file

@ -27,16 +27,13 @@ var GetTileAt = function (tileX, tileY, nonNull, layer)
if (IsInLayerBounds(tileX, tileY, layer))
{
console.log("tile in bounds", tileX, tileY)
var tile = layer.data[tileY][tileX] || null;
if (tile === null)
{
console.log("null tile", tileX, tileY)
return null;
}
else if (tile.index === -1)
{
console.log("null tile", tileX, tileY)
return nonNull ? tile : null;
}
else

View file

@ -37,9 +37,10 @@ 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, tile.width, tile.height);
layer.data[tileY][tileX] = new Tile(layer, tile.index, tileX, tileY, layer.tileWidth, layer.tileHeight);
}
layer.data[tileY][tileX].copy(tile);
}
@ -48,6 +49,7 @@ 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
@ -55,7 +57,6 @@ 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;
@ -66,7 +67,7 @@ var PutTileAt = function (tile, tileX, tileY, recalculateFaces, layer)
{
CalculateFacesAt(tileX, tileY, layer);
}
return newTile;
};

View file

@ -248,6 +248,9 @@ var DynamicTilemapLayer = new Class({
this.setSize(tilemap.tileWidth * this.layer.width, tilemap.tileHeight * this.layer.height);
this.initPipeline('TextureTintPipeline');
console.log("layer sizes")
console.log(this.layer.tileWidth,this.layer.tileHeight)
},
/**

View file

@ -25,7 +25,6 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
var renderTiles = src.culledTiles;
var tileCount = renderTiles.length;
if (tileCount === 0)
{
return;
@ -75,8 +74,8 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
for (var i = 0; i < tileCount; i++)
{
var tile = renderTiles[i];
var tile = renderTiles[i];
var tileset = gidMap[tile.index];
if (!tileset)
@ -85,21 +84,20 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
}
var image = tileset.image.getSourceImage();
var tileTexCoords = tileset.getTileTextureCoordinates(tile.index);
var tileTexCoords = tileset.getTileTextureCoordinates(tile.index);
if (tileTexCoords)
{
var width = 0;
var height = 0;
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
width = tileset.tileWidth;
width = tileset.tileHeight;
} else {
width = tile.width;
height = tile.width
}
halfWidth = width / 2;
halfHeight = height / 2;
@ -118,17 +116,18 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPe
}
ctx.globalAlpha = alpha * tile.alpha;
ctx.drawImage(
image,
tileTexCoords.x, tileTexCoords.y,
width, height,
tileset.tileWidth, tileset.tileHeight,
-halfWidth, -halfHeight,
width, height
);
ctx.restore();
}
}
ctx.restore();