我目前正在用Konva.js在几个堆叠的Konva.js上平铺许多PNG图像。PNG包含不透明,不需要拖动或命中框。瓷砖经常被更换,这似乎很好地适用于尺寸在30×30左右的中型网格。一旦瓷砖开始增长到大约100x100,甚至60x60,当替换单个瓷砖时,性能就会开始变慢。
我已经开始研究“分块”块,即将瓷砖添加到较小的FastLayer组中。例如,单个100x100 FastLayer将被划分为几个10x10 FastLayers。当单个瓷砖发生变化时,想法是只有该块应该重新呈现,理想情况下,应该加快整个呈现时间。
这是一个很好的设计尝试,还是我应该尝试另一种方法?我查看了Konva.js文档中的性能技巧,但没有看到任何与本例直接相关的内容。
发布于 2017-03-14 13:55:44
因此,经过一些研究和修补,我发现了最快的方法来渲染~4000张图片。
发布于 2017-09-10 02:08:58
缓存无疑有助于性能,但隐藏也是如此。Konva不做任何视图筛选(或者我没有最后研究过这个)。下面是我用来在我的Konva策略游戏中隐藏岛屿形状的代码。
stage.on('dragmove', function() {
cullView();
});
function cullView() {
var boundingX = ((-1 * (stage.x() * (1/zoomLevel)))-(window.innerWidth/2))-degreePixels;
var boundingY = ((-1 * (stage.y() * (1/zoomLevel)))-(window.innerHeight/2))-degreePixels;
var boundingWidth = (2 * window.innerWidth * (1/zoomLevel)) + (2*degreePixels);
var boundingHeight = (2 * window.innerHeight * (1/zoomLevel)) + (2*degreePixels);
var x = 0;
var y = 0;
for (var i = 0; i < oceanIslands.length; i++) {
x = oceanIslands[i].getX();
y = oceanIslands[i].getY();
if (((x > boundingX) && (x < (boundingX + boundingWidth))) && ((y > boundingY) && (y < (boundingY + boundingHeight)))) {
if (!oceanIslands[i].visible()) {
oceanIslands[i].show();
oceanIslands[i].clearCache();
if (zoomLevel <= cacheMaxZoom) {
oceanIslands[i].cache();
}
}
} else {
oceanIslands[i].hide();
}
}https://stackoverflow.com/questions/42729872
复制相似问题