【发布时间】:2020-12-07 15:45:32
【问题描述】:
我有一个基于position 向上、向下、向左和向右滚动的背景,我想知道每次position 更改时使用drawImage() 与仅绘制整个背景是否有任何显着的性能差异一次并使用canvas.style移动画布
使用 canvas.drawImage()
//cut piece and draw image to fill canvas every time position changes
canvas.drawImage(backgroundImg, 0 + positionX, 0 + positionY, c.width, c.height, 0, 0, c.width, c.height);
VS
使用 canvas.style
canvas.width = widthofbackgroundImg;
canvas.height = heightofbackgroundImg;
//draw entire background only once
canvas.drawImage(backgroundImg, 0, 0, widthofbackgroundImg, heightofbackgroundImg);
..那么
//move the entire canvas on every position change
canvas.style.left = positionX;
canvas.style.up = positionY;
【问题讨论】:
标签: javascript html css canvas