mirror of
https://github.com/photonstorm/phaser
synced 2024-11-28 07:31:11 +00:00
Add flip capability to dynamic webgl & canvas tilemap renderers
This commit is contained in:
parent
6f4f571f98
commit
6d1b17258b
3 changed files with 22 additions and 4 deletions
|
@ -31,15 +31,28 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, gameObject, interpol
|
|||
var tileTexCoords = tileset.getTileTextureCoordinates(tile.index);
|
||||
if (tileTexCoords === null) { continue; }
|
||||
|
||||
var halfWidth = tile.width / 2;
|
||||
var halfHeight = tile.height / 2;
|
||||
|
||||
ctx.save();
|
||||
ctx.translate(tile.worldX - halfWidth, tile.worldY - halfHeight);
|
||||
|
||||
if (tile.flipX || tile.flipY)
|
||||
{
|
||||
ctx.scale(tile.flipX ? -1 : 1, tile.flipY ? -1 : 1);
|
||||
}
|
||||
|
||||
renderer.setAlpha(gameObject.alpha * tile.alpha);
|
||||
|
||||
ctx.drawImage(
|
||||
image,
|
||||
tileTexCoords.x, tileTexCoords.y,
|
||||
tile.width, tile.height,
|
||||
tile.worldX, tile.worldY,
|
||||
-halfWidth, -halfHeight,
|
||||
tile.width, tile.height
|
||||
);
|
||||
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
|
|
|
@ -30,12 +30,17 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, gameObject, interpola
|
|||
var tileTexCoords = tileset.getTileTextureCoordinates(tile.index);
|
||||
if (tileTexCoords === null) { continue; }
|
||||
|
||||
var frameWidth = tile.width * (tile.flipX ? -1 : 1);
|
||||
var frameHeight = tile.height * (tile.flipY ? -1 : 1);
|
||||
var frameX = tileTexCoords.x + (tile.flipX ? tile.width : 0);
|
||||
var frameY = tileTexCoords.y + (tile.flipY ? tile.height : 0);
|
||||
|
||||
batch.addTileTextureRect(
|
||||
texture,
|
||||
x + tile.worldX, y + tile.worldY, tile.width, tile.height, alpha * tile.alpha, tile.tint,
|
||||
scrollFactorX, scrollFactorY,
|
||||
textureWidth, textureHeight,
|
||||
tileTexCoords.x, tileTexCoords.y, tile.width, tile.height,
|
||||
frameX, frameY, frameWidth, frameHeight,
|
||||
camera,
|
||||
renderTarget
|
||||
);
|
||||
|
|
|
@ -385,8 +385,8 @@ var SpriteBatch = new Class({
|
|||
// Inset UV coordinates by 0.5px to prevent tile bleeding
|
||||
var u0 = (rectX + 0.5) / textureWidth;
|
||||
var v0 = (rectY + 0.5) / textureHeight;
|
||||
var u1 = (rectX - 0.5 + width) / textureWidth;
|
||||
var v1 = (rectY - 0.5 + height) / textureHeight;
|
||||
var u1 = (rectX - 0.5 + rectW) / textureWidth;
|
||||
var v1 = (rectY - 0.5 + rectH) / textureHeight;
|
||||
|
||||
mva = cameraMatrix[0];
|
||||
mvb = cameraMatrix[1];
|
||||
|
|
Loading…
Reference in a new issue