Advice on 2D game with collision

hi all,
I’m developing a basically simple game in phaser, but when trying to find a working setup, I feel like getting lost in multiple setups and I’m not finding something satisfying.
Would be great if someone can help here.

Here is my idea:

  • the game is played on a static background image
  • there are different images/sprites moving over the background image
  • I want to detect collisions between the sprites and certain areas of the background image
    • not all sprites collide with the same areas
    • the areas of the background image where collisions happen can have any shape, I would like the collisions to be as precise as possible
    • for some collisions I want to get a callback executed while others should collide according to the physics configured

I have tried quite a few things:

  • arcarde and matter physics → from my understanding, only matter physics can work with tilemap based collisions which I assume I need to get precise enough collisions
  • created tilemaps with Tiled and added multiple layers so different object can collide with different layers… spent a lot of time setting matter collision categories, but did not get it to work
  • adding a tileset image for the background (2000x1600 pixels) and also for some smaller images makes the game incredibly slow, so I added a separate image that is independent from the tileset… but that’s tricky as some of the images where I need this are moving and are part of the physics, so I need to constantly keep the image in sync

Are my ideas so unusual? I’m very grateful for anyone who have advice or examples of similar setups.
thanks!

I figured out a reasonable way on how to do this:
for each tile that is active in collisions, I need to set the matter collision category on the tile’s matterBody.
To separate different objects, I configured an int property “collides” in tiled.
Code looks like this:


const tile = collisionLayer.getTileAt(x,y);
if(tile?.properties.collides && tile.physics){
  if(tile.properties.collides===1){
    tile.physics.matterBody.setCollisionCategory(COLLISION_CATEGORY_BLOCK);
    tile.physics.matterBody.setCollidesWith(BLOCK_COLLIDESWITH);
    tile.physics.matterBody.type = TYPE_BLOCK; // this is a custom property that helps me detect the colliding objects when a collision has happened
  }
}

Will share the full game here once it’s ready.
If anyone has better ideas on how to achieve what I’m trying to do, I happy to hear about them.