Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

tilelayer z index issue


kepha
 Share

Recommended Posts

Hey guys, this is my first post here on the forums. Please excuse this question as I know z indexing has been asked before but as I searched I still didn't find a solution to my specific issue.

 

I currently have 2 layers in a map, the ground and walls or buildings. like so:

 

V0sguVi.png

 

loading these from tile I have 2 layers:

this.floorlayer = this.map.createLayer('ground');    this.buildinglayer = this.map.createLayer('building');

Which to my understanding creates what is effectively treated in the engine as 2 large sprites?

 

So right now my player is sort of sandwiched between the 2 layers meaning the player sprite draws above the ground and below the walls, resulting in half correct functionality.

I would like to have a z indexing sort something like this example:

http://phaser.io/examples/v2/groups/depth-sort#gv

 

but adding my player and building layer to a group together and sorting them doesn't give me the results I want. it just returns the same as what I already have.

The building layer in the image only shows 1 building but actually on a larger map may have several buildings. Does anybody know the best way for me to achieve this. My thoughts are to try and split the layer up into its individual sprites so I could potentially do a working sort against them all individually, but I dont know how to achieve this in phaser. 

 

Alternatively I could just split the front and back of the house into even more layers... but this isnt really ideal

 

Thanks.

 

Kepha

Link to comment
Share on other sites

probably worth visualizing your requirement...

 

i've not done this before but my first thought was to set collision at a certain "height" (red line), and have those layers below the line on the ground level

 

on a side note, when the player walks through the door, i'd be tempted to alpha out that front wall slightly, so the player can be seen inside the house... but then you need to visually account for the collision portion (place cupboards there?) ...unless you're just not putting any gameplay elements behind the wall, in case I guess you could just leave it obscured. but it may seem odd that the player then can't move slightly further down inside the house.

 

let's see what other people say.. I'm sure there are better solutions!

 

also have you thought have making your house interiors separate areas, and only show the external? see here: http://browserquest.mozilla.org/  (there's an open building if you go upwards)

post-16536-0-83304600-1445701793.jpg

post-16536-0-29499000-1445702502.jpg

Link to comment
Share on other sites

Hey JMP909, 

 

Thanks for your reply, the visualisations you supplied are exactly what I am trying to achieve. I have considered splitting the map up like you advised (below the red line being on the ground level etc) but it involves then splitting the house up into several layers as the player is also able to walk behind the house too so I face the same issue there. I would prefer to find a more elegant solution if possible... 

I would also like to avoid preventing the character access to the floor by the walls, I will of course change the alpha or add a shadow to show the players location. 

 

Would you mind sharing with me the source of the character sprites you used in your example? 

I am wondering if I shouldnt be using layers for the houses, maybe I should be drawing them in a different way so I can interact with them in groups differently... 

 

Kepha

Link to comment
Share on other sites

  • 2 weeks later...
 Share

  • Recently Browsing   0 members

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