Jump to content

Size of platform in Layer


Recommended Posts

Very sorry if someone has asked this before, but I searched the internet for two days now and I have yet to find the answer to this.

So, what I want to know is how can I tell the size (width, height) of the platform that a player/enemy is standing on, with platforms that are based on a tilemap/layer?

Take for example this game phase example starstruck: https://phaser.io/examples/v2/games/starstruck

How can I tell the size of that platform the mascot falls on first? 

Why do I want to know this? I want to know so that I can place enemies on the map, have them go back and worth without falling off a platform.

I have seen this be done when platforms are created as a group, but not with platforms in a layer.

Thank you very much for any help.

Link to comment
Share on other sites

Turns out that in the callback function of a collide sprite and layer you know the tile and the index of the tile the sprite hit, so instead of testing on the length one can test based on if the index of the tile is a tile type that is the end of platform tile. So you can tell based on the terrain rather than platform length when sprite should turn.

        this.game.physics.arcade.collide(this, layer, function (sprite, tile) {
            var i = tile.index;
            if (i == 1 || i == 6 || i == 7 || i == 8) {
                sprite.body.velocity.x *= -1;



Link to comment
Share on other sites


  • Recently Browsing   0 members

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