Jump to content

Collision performance


Recommended Posts

Let's get straight to the point - assuming we have such iteration in my state's update function:

for (vehicle in GameSpace.container.vehicles) {
for (tile in GameSpace.container.mapTiles) {
if (GameSpace.container.mapTiles[tile]) {
GameSpace.container.mapTiles[tile].sprite, GameSpace.container.vehicles[vehicle].sprite

GameSpace is my namespace for the app. Each "sprite" property of both "vehicles" and mapTiles is an instance Phaser.Sprite. There are around 300 tile sprites on the map. When vehicle count increases to let's say 8, fps tends to drop drastically on medium class machines (eg. without at least gt760 graphic card). My call is that it's the collision detection.


Question is - will using tile maps instead of sprites acting as tiles boost the performance or using groups aid the fps drop (I'm suspect there's an iteration down there somewhere also, but still..)? Is Phaser actually fit for such amount of objects colliding? 


Also, is there any way to handle collision like by "events" on sprites, eg. instead of calling "game.physics.colliide" adding "onCollide" function to sprite?


Cheers for the answer in advance.

Link to comment
Share on other sites

How many collision checks are actually being performed every frame here? I assume you're doing something to limit the quantity, so that objects blatantly out of range of each other aren't checked?


My first thought would be to disable the quadtree, especially if the sprites vary in size a lot and you're not using group vs. x anyway, but next would be to check how many iterations are actually going on.

Link to comment
Share on other sites

Per frame it'll be 7 vehicles multiplied by around 300 tiles (all) available on the map, which gives us 2100 loop passes. Each sprite's size is 32x32, both for tiles and vehicles. Afaik, based on what I saw in the source code, quadtree can be disabled just by setting "game.physics.quadTree" to false (or deleting the property)?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...