截至目前,我在屏幕外画布上渲染一张地图,然后将其复制到主帆布中,因此我不必在地图上重新渲染每个框架上的每个对象,wich真的变得很懒惰,我的远场帆布需要相对较大以适合整个地图,整个画布都会被复制到普通的癌症上,每个框架也不是那样的表现,所以我的问题是:有什么方法可以将画布的一部分复制到另一个画布上,所以我不必复制整个东西?
As of right now Im rendering a map once to an offscreen canvas, wich then gets copied to the main canvas every frame, so I dont have to re-render every object on my map every frame, wich gets really laggy, my offscreen canvas needs to be relativly large to fit the whole map tho and the whole canvas gets copied onto the normal canas every frame wich also isn't that performant, so my question is; is there any way to only copy a section of a canvas to another canvas, so I dont have to copy the whole thing?
发布评论
评论(2)
您可以
You can
drawImage
your canvas:/code>
允许您根据X/y坐标提取图像数据和宽度&身高,
允许您将其放在X/Y坐标处。
或使用
getImageData(sx, sy, sw, sh)
allows you to extract image data based on a X/Y coordinate and a width & height, and
putImageData(imageData, dx, dy)
allows you to place it at a X/Y coordinate.
Or use drawImage, that allows you to use the existing canvas as "input" directly, and you can specify X/Y and width/height for both the origin and the target: