2017-09-12 23:58:25 +00:00
|
|
|
var GameObject = require('../../GameObject');
|
|
|
|
|
2017-08-22 23:26:17 +00:00
|
|
|
var StaticTilemapCanvasRenderer = 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-08-22 23:26:17 +00:00
|
|
|
gameObject.upload(camera);
|
|
|
|
|
2017-11-01 17:55:01 +00:00
|
|
|
var tiles = gameObject.tiles;
|
2017-08-22 23:26:17 +00:00
|
|
|
var tileWidth = gameObject.tileWidth;
|
|
|
|
var tileHeight = gameObject.tileHeight;
|
|
|
|
var frame = gameObject.frame;
|
|
|
|
var ctx = renderer.gameContext;
|
|
|
|
var tileCount = tiles.length;
|
|
|
|
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
|
|
|
var boundsX = camera.scrollX;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
for (var index = 0; index < tileCount; ++index)
|
|
|
|
{
|
|
|
|
var tile = tiles[index];
|
|
|
|
ctx.drawImage(image, tile.frameX, tile.frameY, tileWidth, tileHeight, tile.x, tile.y, tileWidth, tileHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.restore();
|
2017-05-30 16:55:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = StaticTilemapCanvasRenderer;
|