# Tag Info

37

I'm not familiar with Terraria, but that can be easily done using a flood-fill algorithm. Instead of pixel, you check the tiles, and for each tile checked, you evaluate if the algorithm can proceed checking other tiles, while storing in an array or list which objects are found during the process. The algorithm starts at the tile where the character is at. ...

4

Generally game mechanics should not behave differently depending on whether or not the player observes the event. The player expects that the game mechanics outside of their field of view behave exactly as those inside their field of view. It is very immersion-breaking when they leave an area, enter it again shortly afterwards and apparently in the mean-time ...

3

There are 2 hard problems in computer science. Naming things, cache invalidation and off-by-one errors. This is a cache invalidation problem. If you have a record of "is this inside", whenever a block is placed or removed it is pretty easy to update it and its region via a flood fill. To optimize this you may want to have a set of tiers of "insideness". ...

3

Like @Ferreira da Selva said, try the flood fill algorithm. Though, you can use a few different criteria when running the algorithm to determine whether it is enclosed. For example, for each tile you check if there is a background tile, and if there isn't, then you know that it isn't enclosed. Or you could have it perform a deferred execution by separating ...

2

Treat all the chunks around player, as offsets (shown in one axis but applies for both): -3 -2 -1 0 +1 +2 +3 <- 7 offsets for 1 axis; for x * y that would be 49 offsets. 0, 0 is the offset where the player is - the origin of "player space". 3, -2 might be roughly to the northeast or whatever, depending on your coordinate system setup, and so forth. Now ...

2

There isn't any libGDX function for this particular problem, but it should be something like: Vector2 closestToFinger(Vector2[] vectorsArray, Vector2 touchPosition) { float shortestDist = 0; Vector2 closestVector = null; for(point in vectorsArray){ float dst2 = touchPosition.dst2(point); if(closesVector == null || dst2 &...

2

As explained in the answer by Romen, there aren't many applicable data structures which are not based on rectangles. But there are a couple other optimizations you can do for circle-circle collisions which could reduce your demand for a more optimized data-structure. Compare the square of the distance with the square of the radius. If you want to check if a ...

2

I can't recommend a structure that actually implements what you're asking for, but it definitely won't work like a quad tree. It may not be a tree at all and it might not even exist... A quad tree has a tree structure because each node represents the node above it divided into four quadrants. At any level these four quadrants cover all of the space covered ...

2

As Kromster alludes, this apparent problem occurs because of the small scale of your example. Usually when we reach for sparse octrees, we have more than two levels of subdivision. Here's your same 2D quadtree example, but with 4 levels of subdivision instead of 2: You can see how, even in the worst case where we have a cluster of detailed content spanning ...

2

The simple answer would be to add the object's pointer to both cells. As it exists in both cells, to not include it in both cells would be to circumvent the purpose of having the tree to begin with. The more complicated answer would be to reexamine the purpose for which you're using the spatial partitioning. If this is for graphics and culling, the answer ...

1

No game development police will come to arrest you if you try to store a non-manifold mesh in a spatial partition data structure for collision detection purposes. No law of physics will cause your computer to implode if you do this. So no, it's not a requirement to have a manifold mesh, nor is it impossible to use non-manifold geometry in a spatial ...

1

How deep are your quadtrees? How many elements do you tolerate in a leaf node before you subdivide? How are your entities spread out through the world? If it is extremely uneven, with just a few big clumps here and there, I can see how quadtrees would help. But if it is better spread out than that, I would use a grid instead of a quadtree. A grid is much ...

1

The library you're using should do what you want. I tried it — demo here, with the default power of two setting (5): You have to specify the “area of interest” in the retrieve function. The library wants retrieve to take a rectangle, so pass in a rectangle centered on the player.

1

Generally with a spatial hash, you will have to grab stuff from more than one cell. This is because even if each cell is larger than a screen width, you could always be close to the edge of your current cell. If each one is larger than a screen width, you could pull the nearest 3x3 cells, and if not, you'll have to loop through "all visible cells" for ...

Only top voted, non community-wiki answers of a minimum length are eligible