Jump to content

How to iterate through collidable tiles in a State?


Tangaroa
 Share

Recommended Posts

Working from meanderingleaf's example of a platformer game, https://github.com/meanderingleaf/PhaserBookExamples/blob/master/platformer/src/states/Level1.js

Land tiles are defined by: this.map.setCollisionBetween(6,25,true,this.layer);

Unlike the other objects in the level, these tiles are not added to a Group.

I would like to draw rectangles around the collision areas of the land tiles using this.game.debug.geom(), and preferably other collidables as well. However, I am having trouble finding where they are inside the State object. It is not clear what the numbers in this.collideIndexes are indexes to. this.map.tiles[] holds arrays of three integers, not Tiles, and the locations cover where the tiles are placed in their spritesheet and not the tiles are placed inside the level. Where do I find the collidable objects that were created by map.setCollisionBetween?



I have some additional questions about managing collisions with land in platformers. How do you...

1. Change the collision area of the land tiles to a thin rectangle so the player could jump up partway through the bottom of the tile?
2. Allow the player to move through a tile, but only from one direction? (jump up from below)
3. Allow the player or an enemy to jump down through a tile they are standing on, without turning off the tile's collisions for everything else?
4. Allow certain groups of moving objects to move through land tiles?

Link to comment
Share on other sites

First try

tilemapLayer.debug = true;

That will show the colliding edges.

The tiles themselves aren't display objects. The only display objects are the TilemapLayers, which are a special kind of Sprite.

Tilemap#collideIndexes refers to Tile#index, a tile-in-tileset identifier.

The per-layer tile data is in Tilemap#layers[LAYER].data.

  1. This is a little tricky. I think you could add a collision callback, check the overlap amount, and cancel the collision if the overlap is too small.
  2. You can modify, e.g., Phaser.Tile#collideUp. Do it after all the setCollision* work because you don't want to recalculate collision edges (which would reset it).
  3. Probably in a collision callback.
  4. Probably in a collision callback. If the group can move through any tile, you can just skip calling collide for that group.

See the Tilemap notes in Phaser.Physics.Arcade#collide too.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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