phaser/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayerCanvasRenderer.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

var GameObject = require('../../GameObject');
var DynamicTilemapLayerCanvasRenderer = function (renderer, gameObject, interpolationPercentage, camera)
2017-06-09 04:00:12 +00:00
{
if (GameObject.RENDER_MASK !== gameObject.renderFlags || (gameObject.cameraFilter > 0 && (gameObject.cameraFilter & camera._id)))
2017-06-09 04:00:12 +00:00
{
return;
}
gameObject.cull(camera);
var renderTiles = gameObject.culledTiles;
var length = renderTiles.length;
2017-08-25 02:46:33 +00:00
var image = gameObject.frame.source.image;
var tileset = this.tileset;
// var scrollFactorX = gameObject.scrollFactorX;
// var scrollFactorY = gameObject.scrollFactorY;
// var alpha = gameObject.alpha;
2017-08-25 02:46:33 +00:00
var tx = gameObject.x - camera.scrollX * gameObject.scrollFactorX;
var ty = gameObject.y - camera.scrollY * gameObject.scrollFactorY;
var ctx = renderer.gameContext;
ctx.save();
ctx.translate(tx, ty);
ctx.rotate(gameObject.rotation);
ctx.scale(gameObject.scaleX, gameObject.scaleY);
ctx.scale(gameObject.flipX ? -1 : 1, gameObject.flipY ? -1 : 1);
for (var index = 0; index < length; ++index)
2017-08-25 02:46:33 +00:00
{
var tile = renderTiles[index];
var tileTexCoords = tileset.getTileTextureCoordinates(tile.index);
if (tileTexCoords === null) { continue; }
2017-08-25 02:46:33 +00:00
ctx.drawImage(
image,
tileTexCoords.x, tileTexCoords.y,
tile.width, tile.height,
tile.worldX, tile.worldY,
tile.width, tile.height
2017-08-25 02:46:33 +00:00
);
}
ctx.restore();
2017-06-09 04:00:12 +00:00
};
module.exports = DynamicTilemapLayerCanvasRenderer;