2017-09-12 23:58:25 +00:00
|
|
|
var GameObject = require('../../GameObject');
|
|
|
|
|
2017-11-09 18:18:23 +00:00
|
|
|
var StaticTilemapLayerCanvasRenderer = function (renderer, gameObject, interpolationPercentage, camera)
|
2017-05-30 16:55:15 +00:00
|
|
|
{
|
2017-09-12 23:58:25 +00:00
|
|
|
if (GameObject.RENDER_MASK !== gameObject.renderFlags || (gameObject.cameraFilter > 0 && (gameObject.cameraFilter & camera._id)))
|
2017-05-30 16:55:15 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-08-15 22:51:37 +00:00
|
|
|
|
2017-11-18 14:31:59 +00:00
|
|
|
gameObject.cull(camera);
|
2017-08-22 23:26:17 +00:00
|
|
|
|
2017-11-18 14:31:59 +00:00
|
|
|
|
|
|
|
var renderTiles = gameObject.culledTiles;
|
2017-11-14 21:35:18 +00:00
|
|
|
var tileset = this.tileset;
|
2017-08-22 23:26:17 +00:00
|
|
|
var frame = gameObject.frame;
|
|
|
|
var ctx = renderer.gameContext;
|
2017-11-18 14:31:59 +00:00
|
|
|
var tileCount = renderTiles.length;
|
2017-08-22 23:26:17 +00:00
|
|
|
var image = frame.source.image;
|
|
|
|
var tx = gameObject.x - camera.scrollX * gameObject.scrollFactorX;
|
|
|
|
var ty = gameObject.y - camera.scrollY * gameObject.scrollFactorY;
|
2017-08-23 22:27:51 +00:00
|
|
|
|
2017-08-22 23:26:17 +00:00
|
|
|
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);
|
2017-11-18 14:31:59 +00:00
|
|
|
renderer.setAlpha(gameObject.alpha);
|
2017-08-22 23:26:17 +00:00
|
|
|
|
|
|
|
for (var index = 0; index < tileCount; ++index)
|
|
|
|
{
|
2017-11-18 14:31:59 +00:00
|
|
|
var tile = renderTiles[index];
|
2017-11-03 16:52:57 +00:00
|
|
|
|
2017-11-14 21:35:18 +00:00
|
|
|
var tileTexCoords = tileset.getTileTextureCoordinates(tile.index);
|
|
|
|
if (tileTexCoords === null) { continue; }
|
|
|
|
|
|
|
|
ctx.drawImage(
|
|
|
|
image,
|
|
|
|
tileTexCoords.x, tileTexCoords.y,
|
|
|
|
tile.width, tile.height,
|
2017-12-01 15:40:55 +00:00
|
|
|
tile.pixelX, tile.pixelY,
|
2017-11-14 21:35:18 +00:00
|
|
|
tile.width, tile.height
|
|
|
|
);
|
2017-08-22 23:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.restore();
|
2017-05-30 16:55:15 +00:00
|
|
|
};
|
|
|
|
|
2017-11-09 18:18:23 +00:00
|
|
|
module.exports = StaticTilemapLayerCanvasRenderer;
|