전체 화면 캔버스에 3 개의 이미지가 그려져 있습니다. 창 크기를 조정하면 이러한 이미지의 위치가 바뀝니다. 그러나, 그것은 Firefox에서 매우 glitchy 인 것처럼 보입니다.HTML 캔버스 이중 버퍼링 프레임 속도 문제
이중 버퍼링이이 문제를 해결해야한다는 것을 읽었지 만 다음 위치를 알 수 없을 때 버퍼를 두 번 어떻게 사용할 것인지 궁금합니다. 즉, 미래에 무엇이 버퍼링되어야 하는지를 결정할 수 없으므로, 이것이 어떻게 가능할까요?
여기는 할 수있는 한 가지 근원이지만, 나는 페도르가 설명하려고하는 개념을 완전히 이해하지 못합니다.
Does HTML5/Canvas Support Double Buffering?
은 지금까지 나는
$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 < 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);
};
}