A downloadable example for Windows

Download NowName your own price

Spatial Hashing example for GameMaker Studio 1.4x

May 25, 2024 - Fixed out of bounds memory error

Left click - create an entity (object) that registers on the grid

Right click - destroy an entity (object) and unregisters itself from the grid (which also creates a new entity randomly on the grid)

Mousing over the grid will highlight the cell and will tell you how many entities/objects are registered on that cell

Spatial hashing splits the room into an array grid, and objects are registered to cells of the grid based on their position.

Spatial hashing is useful for detecting collisions and reducing the calculation of distance algorithms, such as the nearest neighbor algorithm.

For example, the function instance_nearest checks all instances, which if used too much will take too much CPU power, but in a spatial hash, one just has to check the objects in the nearby cells.

GameMaker Studio 2 version coming eventually.


Download

Download NowName your own price

Click download now to get access to the following files:

SpatialHashing.exe 2.3 MB
SpatialHashing.gmz 11 kB

Leave a comment

Log in with itch.io to leave a comment.