var DynamicTilemapLayerCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix){ src.cull(camera); var renderTiles = src.culledTiles; var tileCount = _AN_Read_length('length', renderTiles); if (tileCount === 0) { return ; } var camMatrix = renderer._tempMatrix1; var layerMatrix = renderer._tempMatrix2; var calcMatrix = renderer._tempMatrix3; layerMatrix.applyITRS(src.x, src.y, src.rotation, src.scaleX, src.scaleY); camMatrix.copyFrom(camera.matrix); var ctx = renderer.currentContext; var gidMap = src.gidMap; ctx.save(); if (parentMatrix) { camMatrix.multiplyWithOffset(parentMatrix, - camera.scrollX * src.scrollFactorX, - camera.scrollY * src.scrollFactorY); layerMatrix.e = src.x; layerMatrix.f = src.y; camMatrix.multiply(layerMatrix, calcMatrix); calcMatrix.copyToContext(ctx); } else { layerMatrix.e -= camera.scrollX * src.scrollFactorX; layerMatrix.f -= camera.scrollY * src.scrollFactorY; layerMatrix.copyToContext(ctx); } var alpha = camera.alpha * src.alpha; if (!renderer.antialias || src.scaleX > 1 || src.scaleY > 1) { ctx.imageSmoothingEnabled = false ; } for (var i = 0; i < tileCount; i++ ){ var tile = renderTiles[i]; var tileset = gidMap[tile.index]; if (!tileset) { continue ; } var image = tileset.image.getSourceImage(); var tileTexCoords = tileset.getTileTextureCoordinates(tile.index); if (tileTexCoords) { var halfWidth = tile.width / 2; var halfHeight = tile.height / 2; ctx.save(); ctx.translate(tile.pixelX + halfWidth, tile.pixelY + halfHeight); if (tile.rotation !== 0) { ctx.rotate(tile.rotation); } if (tile.flipX || tile.flipY) { ctx.scale((tile.flipX)? -1: 1, (tile.flipY)? -1: 1); } ctx.globalAlpha = alpha * tile.alpha; ctx.drawImage(image, tileTexCoords.x, tileTexCoords.y, tile.width, tile.height, - halfWidth, - halfHeight, tile.width, tile.height); ctx.restore(); } } ctx.restore(); } ; module.exports = DynamicTilemapLayerCanvasRenderer;