I am currently programming a small game using canvas. For the game I need some kind of fog that hides most of the map, and only a small area around the player should be visible. Therfor I use the second canvas to overlay the one where the game takes place and fill it with a gradient (from transparent to black):
function drawFog(){
fogc.clearRect(0,0,700,600);
var grd=fogc.createRadialGradient(player.getPosX(),player.getPosY(),0,player.getPosX(),player.getPosY(),100);
grd.addColorStop(0,"rgba(50,50,50,0)");
grd.addColorStop(1,"black");
fogc.fillStyle=grd;
fogc.fillRect(0,0,700,600);
}
Unfortunately, this causes huge performance problems, as it will be redrawn for each frame.
I wanted to ask if there could be a better solution to achieve the same effect with better performance.
source
share