A demonstration of different approaches for scaling collision detection using the Phaser game framework.
The demo allows for the increase/decrease of game objects on screen so as to determine how many simultaneous game objects can be checked for collisions before frame rate drops occur.
Naive: perform n x n checks, no space partitioning used
BSP: use a binary space partition (BSP) tree to place game objects into partitions, and then perform collision checks only in partitions.
Sweep & Prune: sort game objects according to x value, then only perform checks against game objects in the same "column" of objects.
Arcade Physics: use the Phaser-provided Arcade Physics collision detection algorithm.
In general, Sweep & Prune > BSP > Arcade Physics > Naive.
Code generated by Claude (Sonnet 4.6).
Uses Phaser 4.x
Art assets from Kenney Assets, with gratitude.