Sunday, October 22, 2017

2d - How do you handle uneven tiles while rendering a tile map?


enter image description here



Here is what I want to do with my tile map that I am unsure of. As you can see the top walls are way larger then the bottom and side ones (this is also an issue with my corners which are odd shapes [more like an L then a square] as well as larger then the 40x40px that my current tiles are).


enter image description here


I have also attached the tile sheet I am using for the tiles to show you what the corners and tops look like compared to the rest of the tiles.


What I’m thinking is I might be able to just draw them using the same array I have if I use the tiles width and height instead of a set WxH? I dont know how well this will work, but were the blocks that will have different values will be blocks the player/NPCs can’t step on then it may not be an issue, again I’m not even sure if that is a viable solution.


My code in case you want to see how I'm currently handling it: Map.java (pastebin) (edit:im not handling it, meant how I'm currently doing the map)


tl;dr - how can I take take my 2d looking tile map and change it to have different size tiles? or is there a better way to do what I am trying to do? Is there a name of a method that I should be looking for while googling?



Answer



There are two standard ways of doing this.



  • Break up your non-standard tile sizes into standard tile sizes. So those strips of walls become a "stack" of square tiles that you just know to place together in your level editor. Games like the early Final Fantasy games worked this way.


  • Let any tile piece be taller than your standard tile height. Align tiles to the bottom of your tile rectangle, allowing any extra to draw higher than the usual tile height. When drawing your map, you draw tiles starting from the back (the tile squares higher on the screen), and ending with the bottom tiles (the ones at the bottom of the screen). This ensures that tall tiles in the foreground are properly overlayed on top of tiles in the background. Note that in this approach, your tiles are still limited to a single tile in width.


You can do either or both of these approaches. Even games which do the "break up into stacks of tiles" approach will often allow some objects (trees, etc) to break the tile height limits, and just enforce a top-to-bottom map draw ordering in order to make sure everything layers correctly.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...