I'm working on a game which is beginning to get pretty graphically intensive. There are lots of points, arcs, and gradients that need to be drawn. Problem is that drawing all these graphics is beginning to get slow. RGBA radial gradients seem to take an exceptionally long time to draw when drawn over top of other gradients (ie, for the background).
If there was some way to buffer the graphics, that could save me a lot computations every frame. According to this question graphics buffering can be accomplished by creating a hidden html5 canvas on the html document. Unfortunately this will not work because I need to be able to buffer an undefined number of graphics for the game.
Is there any way to buffer a graphics for an html5 canvas?
The HTML5 canvas has the potential to become a staple of the web, enjoying ubiquitous browser and platform support in addition to widespread webpage support, as nearly 90% of websites have ported to HTML5.
The best canvas optimization technique for animations is to limit the amount of pixels that get cleared/painted on each frame. The easiest solution to implement is resetting the entire canvas element and drawing everything over again but that is an expensive operation for your browser to process.
From http://kaioa.com/node/103
var renderToCanvas = function (width, height, renderFunction) {
var buffer = document.createElement('canvas');
buffer.width = width;
buffer.height = height;
renderFunction(buffer.getContext('2d'));
return buffer;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With