Sign in to follow this  

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:

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.

Share this post

Link to post
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., layer, function (sprite, tile) {
            var i = tile.index;
            if (i == 1 || i == 6 || i == 7 || i == 8) {
                sprite.body.velocity.x *= -1;



Share this post

Link to post
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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.