A way to change a tile's layer ingame?

Aug 11, 2011 at 9:11 PM

Sometimes I want a tile to draw underneath of a game character.  Sometimes I want it to draw on top of a game character.  I think I could make this happen if I could switch the tile from a layer that draws under the character to a layer that draws on top of the character.  Is there a way to do this?

Aug 12, 2011 at 9:34 AM

I suppose you're aiming at something akin to what is done in a tile-based RPG engine. I can think of one way, but it is a bit messy. Basically, clone a layer in your map and have the player render between them by hooking a handler to the AfterDraw event of the bottom layer (or the BeforeDraw event of the top layer) to render your character sprite. By default, your character will be covered by the top layer. However you can then apply your own logic to selectively clear and restore tiles in the top layer. Now I did warn you it is a messy solution! :)

I have yet to come up with an elegant solution for this but I will keep thinking about it.

Aug 12, 2011 at 8:48 PM

Yes, that's what I'm after. 

How do you clear tiles in a layer?  I see a method for cloning a tile to a new layer and a method for cloning or removing a layer, but I do not see a method for clearing tiles in a layer.