我有大约50张图片需要加载,然后我才能展示我的舞台。我想减少请求的数量,加载一个包含我所需要的所有图像的大sprite,然后在任何地方使用它,但偏移量是正确的。就像我们在CSS中使用背景位置属性一样。
在文档里还没有找到任何关于它的东西--这可能吗?
发布于 2021-04-02 14:09:04
对于该用例,可以使用作物属性。
对于每个Konva.Image
实例,只使用一个源映像元素。
const img = new Image();
img.onload = () => {
const part1 = new Konva.Image({
image: img,
cropX: 0,
cropY: 0,
cropWidth: img.width / 2
cropHeight: img.height
});
layer.add(part1);
const part2 = new Konva.Image({
image: img,
cropX: img.width / 2,
cropY: 0,
cropWidth: img.width / 2
cropHeight: img.height
});
layer.add(part2);
layer.batchDraw();
}
img.src = url;
https://stackoverflow.com/questions/66902435
复制相似问题