Jump to content

Understanding Phaser Quadtree


Jerorx
 Share

Recommended Posts

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

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...