CreateJS / EaselJS Strange Performance with certain size shapes

寵の児 提交于 2019-12-05 04:47:06

Solved.

I solved the issue by looping through each shape on tick, and applying a visible = false; if it is out of bounds Updated Fixed Example

//Update the container position based on camera position and zoom
updatePosition = function () {

    var floor = Math.floor;

    var min_x = 0 + Camera.x * Camera.zoom - size;
    var min_y = 0 + Camera.y * Camera.zoom - size;
    var max_x = Screen.width + Camera.x * Camera.zoom + size
    var max_y = Screen.height + Camera.y * Camera.zoom + size;



    mainContainer.x = -Camera.x * Camera.zoom;
    mainContainer.y = -Camera.y * Camera.zoom;

    var shape_count = mainContainer.getNumChildren() - 1;

    for (var i = 0; i <= shape_count; i++) {
        var shape = mainContainer.getChildAt(i);

        if(shape.x < min_x || shape.x > max_x){
            shape.visible = false;
        }
        else if(shape.y < min_y || shape.y > max_y){
           shape.visible = false; 
        }
        else {
            shape.visible = true;
        }

    }

}

What I noticed is, that if the caching-square is smaller than a certain size the framerate drops, so what I did:

var cache_offset = 10 * Camera.zoom;
=>
var cache_offset = 10 * Camera.zoom + 77;

And I played around with that 77 a little, my initial thought was that the caching area has to be in the power of 2, but at zoom:3, adding 77 results in a caching-size of 364x364px and any size above that works fine as well for zoom:3, so I don't know why, but the size of the caching-rectangle somehow causes the framerate to drop.


And there's one typo(not really affecting this issue):

mainStage.snameToPixelsEnabled = true;
=>
mainStage.snapToPixelEnabled = true;

That brought up the framerate by about 2-3fps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!