Jump to content

Arcanorum
 Share

Recommended Posts

So my game has a large game world, with lots of baddies running around that I need to test for collisions with the player, as well as a tilemap with some solid (collidable) tiles.

I understand that using the quadtree technique can help me sort out what is close enough to be considered for collision testing and can save me some collision checks if used right.

 

I have read the docs and the links to the original implementations that the Phaser one is based on, and understand how the concept works, but I can't seem to find any complete explanation of how to get it working in Phaser and any special quirks that Phaser adds.

 

The quadtree example on the Phaser examples page is not helpful. It just throws code at me without explanation.

 

From the scraps of info that I have found from a forum search, I have the following questions:

  1. How does the grouping mechanism relate to how quadtrees work?
  2. Do the physics systems use a quadtree by default? Do I need to create my own?
  3. Are tilemap tiles considered? i.e. I might have some tiles with collides set to true. Will the quadtree factor out distant collision tiles like it would with other physics bodies when checking collisions?

 

Link to comment
Share on other sites

There's really nothing more to it than this:

game.physics.arcade.skipQuadTree = false;

Every physics Body created will automatically use the global quadtree by default (unless disabled on a per body basis).

 

Tilemaps don't use quadtrees btw. Just Sprites.

Link to comment
Share on other sites

Ok, so what about groups?

I have replicated the quadtree example and it works, but if I store the sprites in an array instead of a group the quadtree seems to ignore them. They still collide with each other. How come?

game.physics.startSystem(Phaser.Physics.ARCADE);game.physics.arcade.skipQuadTree = false;aliens = [];for (var i = 0; i < 50; i++){    var s = game.add.sprite(game.world.randomX, game.world.randomY, 'baddies');    game.physics.enable(s, Phaser.Physics.ARCADE);    s.body.collideWorldBounds = true;    s.body.bounce.set(1);    s.body.velocity.setTo(10 + Math.random() * 40, 10 + Math.random() * 40);    aliens[i] = s;}

I know I should be using groups anyway, but suppose I have the need to put stuff in an array. I figured it would work as the collide function works with arrays.

 

Also, about Tilemaps...

I don't know how tile collision is done, so sorry if what I'm about to suggest makes me sound like a doofus.

 

Could I create an object layer to mark out collision boundaries with rectangles then use those instead of doing setCollision for a bunch of tiles?

 

If not, could I use that object layer to mark out where I want physics bodies to be, then create physics bodies in Phaser from this location and size info. This way there will be normal physics bodies in the world that could use the quadtree like any other.

 

I know it sounds hacky, but could it be faster than constantly checking all collidable tiles on a tilemap that are far away like I assume it would normally?

 

I read a while ago that using object layers for collision only works in P2, not Arcade. Is this still the case?

 

Sorry for the abundance of questions. This is stuff I have been wondering for a while. :wacko:

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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