Best practices for arcade collision organizing?

Hi all,
New Phaser user! I have lots of experience with Unity, but I checked out Phaser cuz Unity was overkill/too slow for 2D prototyping. I’m loving it so far!

I’m using the ARCADE physics engine, which is new to me (coming from Unity), but interesting. I’m making a fairly standard 2D action game, so it seems appropriate, but I was wondering if I’m doing things “right” in terms of how I organize collision logic. My current vague plan is to have each sprite be in one of these arrays:

  • environment - walls, lava
  • player - duh
  • enemy - also duh
  • bullet - shot from the enemies (maybe the player too)

Then in update(), for each unique pair (player-enemy, player-environment, etc.), I would run game.physics.arcade.collide(). Except for any pairs with bullet, where I would run overlap() instead (bullets should either go through friendlies, possibly go through environment, definitely go through other bullets, or kill() upon touching the player).

So…does this sound reasonable, or is it over-complicated?

Another design I was thinking was just having each entity call collide() on whatever other ents it cares about. Like, is there any performance difference between…

walls.forEach(wall => collide(wall, this.sprite))
vs.
collide(wallGroup, this.sprite)

…? If there’s no difference, then maybe I just shouldn’t worry about performance for now and let each entity’s update decide who they want to collide with.

Sorry this sounds kind of rambling :slight_smile: Just looking for style advice.

In Phaser 2 this is more performant:

collide(wallGroup, this.sprite)

I see - it actually uses a quadtree, which is rebuilt every call to collide() - good to know!

I think the quad tree is turned off by default, but groups are sorted on one axis before each sprite is checked.