Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML canvas double buffering frame-rate issues
    primarykey
    data
    text
    <p>I have a full-screen canvas with 3 images drawn on it. When I resize the window, these images change position; however, it appears to be very glitchy, more so in Firefox. </p> <p>I've been reading that double-buffering should resolve this issue, but I'm wondering how I would double buffer when the next position is unknown. That is to say, I cannot determine what should be buffered in the future, so how would this be possible?</p> <p>Here is one source that seems doable, but I do not fully understand the concept Fedor is trying to explain. </p> <p><a href="https://stackoverflow.com/questions/2795269/does-html5-canvas-support-double-buffering">Does HTML5/Canvas Support Double Buffering?</a></p> <p>So far I have,</p> <pre><code> $canvas = $('#myclouds')[0]; $canvas_buffer = $('canvas')[0].insertAfter($canvas).css('visibility', 'hidden'); context = $canvas.getContext('2d'); context_buffer = $canvas_buffer.getContext('2d'); clouds_arr = [$canvas, $canvas_buffer]; $(window).resize(function () { drawCanvas(); }; function initCanvas() { // Sources for cloud images var cloud1 = '/js/application/home/images/cloud1.png', cloud2 = '/js/application/home/images/cloud2.png', cloud3 = '/js/application/home/images/cloud3.png'; // add clouds to be drawn // parameters are as follows: // image source, x, y, ratio, adjustment) addCloud(cloud1, null, 125, .03); addCloud(cloud2, null, 75, .15); addCloud(cloud3, null, 50, .55); addCloud(cloud1, null, 125, .97, 300); addCloud(cloud2, null, 70, .85, 300); addCloud(cloud3, null, 45, .5, 300); // Draw the canvas drawCanvas(); } function drawCanvas() { // Reset $canvas.attr('height', $window.height()).attr('width', $window.width()); // draw the clouds var l = clouds.length; for (var i = 0; i &lt; l; i++) { clouds[i].x = ($window.width() * clouds[i].ratio) - clouds[i].offset; drawimage(context, clouds[i]); } } function Cloud() { this.x = 0; this.y = 0; } function addCloud(path, x, y, ratio, offset) { var c = new Cloud; c.x = x; c.y = y; c.path = path; c.ratio = ratio || 0; c.offset = offset || 0; clouds.push(c); } function drawimage(ctx, image) { var clouds_obj = new Image(); clouds_obj.src = image.path; clouds_obj.onload = function() { ctx.drawImage(clouds_obj, image.x, image.y); }; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload