Jerorx Posted October 2, 2016 Share Posted October 2, 2016 Hi, I'm interested in using the QuadTree class of Phaser to retrieve spatially-indexed objects based on their spatial coordinates. But it seems I don't quite understand the "retrieve" part. I'm looking at the quadtree example, and I don't understand it well. I would expect that when you click somewhere in the example, only the green rectangles that intersect or are within the big blue rectangle would be selected, based on their spatial coordinates. However, it doesn't seem to be the case at all, and I don't see any "logic" in the way the green rectangles are selected. Depending on where I click, nearby rectangles are selected (which makes sense), but rectangles very far away from the select zone are selected as well, which seems to me to defeat the purpose of spatial-based selection. In other cases (seemingly random to me), almost all rectangles are selected, which renders the whole thing useless. Never do I manage to select only the rectangles that are in the blue selection zone. Can someone explain it to me? My goal being to be able to select only the rectangles in the blue zone, or at least rectangles closeby. Link to comment Share on other sites More sharing options...
Fatalist Posted October 2, 2016 Share Posted October 2, 2016 You should do the final filtering yourself, it only returns *potentially* intersecting objects. The far-away objects are returned because of the way this particular quad-tree implementation works: when an object to be added intersects 2 regions, it is added to the parent region. This makes querying a bit slow because a lot of objects end up in high-level regions rather than in leafs. For example, the objects that intersect X or Y axes will be added to the root-region and included in every single query-result. A different approach would be to add the object to every leaf that it intersects. samme 1 Link to comment Share on other sites More sharing options...
Recommended Posts