2017-09-12 23:58:25 +00:00
|
|
|
var GameObject = require('../../GameObject');
|
|
|
|
|
2017-08-25 02:46:33 +00:00
|
|
|
var TilemapCanvasRenderer = function (renderer, gameObject, interpolationPercentage, camera)
|
2017-06-09 04:00:12 +00:00
|
|
|
{
|
2017-09-12 23:58:25 +00:00
|
|
|
if (GameObject.RENDER_MASK !== gameObject.renderFlags || (gameObject.cameraFilter > 0 && (gameObject.cameraFilter & camera._id)))
|
2017-06-09 04:00:12 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-08-15 22:51:37 +00:00
|
|
|
|
2017-09-12 23:58:25 +00:00
|
|
|
gameObject.cull(camera);
|
|
|
|
|
2017-08-25 02:46:33 +00:00
|
|
|
var tiles = gameObject.culledTiles;
|
|
|
|
var tileCount = tiles.length;
|
|
|
|
var image = gameObject.frame.source.image;
|
2017-11-03 16:52:57 +00:00
|
|
|
|
|
|
|
// 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 < tileCount; ++index)
|
|
|
|
{
|
|
|
|
var tile = tiles[index];
|
2017-09-12 23:58:25 +00:00
|
|
|
|
2017-11-03 16:52:57 +00:00
|
|
|
if (tile.id <= 0 && gameObject.skipIndexZero)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-08-25 02:46:33 +00:00
|
|
|
ctx.drawImage(
|
2017-11-03 16:52:57 +00:00
|
|
|
image,
|
|
|
|
tile.frameX, tile.frameY,
|
|
|
|
tile.frameWidth, tile.frameHeight,
|
|
|
|
tile.x, tile.y,
|
2017-08-25 02:46:33 +00:00
|
|
|
tile.frameWidth, tile.frameHeight
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.restore();
|
2017-06-09 04:00:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = TilemapCanvasRenderer;
|