How is the touch detection implemented in cocos2d-js v3.13?

Is there some smart algorithm/structure behind (such as quad tree or voronoi diagram) ? Or is the touch detection implemented in naive way by calling all registered listeners and checking if the touch location is inside bounding box of a node?

I am asking bcs i wanna know if a lot of “touchable” nodes on scene can cause performance problems.

Thanks!

Not sure how it works with JS, but last time I checked the C++ code it worked by iterating through the vector of listeners, calling their onTouchBegan functions, and repeating this until it either found a listener that returned “true” and swallowed touches, or reached the end of the vector.

If it’s similar for JS then it’s probably not a high performance cost for each listener, but it probably depends on what you are doing in your onTouchBegan functions. Having lots of listeners, like 100’s or 1000’s of them, might cause problems though, as you would be doing a lot of function calls.


    cc.eventManager.addListener(cc.EventListener.create({
        event: cc.EventListener.TOUCH_ALL_AT_ONCE,
        onTouchesEnded: function(touches, event){
            var touch = touches[0];
            //your code here
        }
    }), this);

Thanks, thats what i wanted to know! I suppose in JS its the same as in C++.