views:

55

answers:

1

I'm wondering what the best way to render a scene made up of multiple-sized tiles, from back to front, with different heights.

Like this: http://www.youtube.com/watch?v=Ahfrxm6ETgA
Important stuff starts at 2:35. Ignore the horrible narration. :P

I'm using VB2008.

So here's what I have right now:

  • My graphics consist of bitmaps that have widths and lengths divisible by 32.
  • Objects have the same dimensions as the graphic they were assigned.
  • Objects have layers, with lower layers being drawn back-to-front before moving onto the next layer (e.g., all objects in layer 0 get rendered before objects in layer 1)
  • ALL objects, regardless of scenery/player/person/entity are stored together in a List of MapObject.

Here is what I have also that I'm not sure to keep

  • Objects are sorted based on not their initial X/Y value, but their X/Y+Height value. That way, objects are rendered based on where they 'touch' the playing field. E.g., X/Y = top of a tree object, X/Y = trunk of the tree object.
  • People (including the player) will be just normal map objects that get rendered and updated within a huge sorted list every frame.

Any suggestions? Right now, fudging around with my code allows my Player (32x64 pixels) to stand infront of a building but has her feet get overlapped with a patch of grass, which doesn't work. However, changing the sorting algorithm makes the player disappear in the building but you can see her feet.

So something is wrong haha.

Anyone have experience with 2D rendering that could help me out?

Also, should my players be included with the list of map objects? Granted, these will only be graphical representations of their data stored elsewhere (won't be cleared when map changes), or should I throw them into a whole new rendering list (which might open whole new problems).

Thank you!~

EDIT: I just read this here http://xnafantasy.wordpress.com/2008/07/22/rendering-dilemmas-z-ordering-grass-and-camera-clipping/

From what he says, he has 4 different layers and then draws the actor between Layer 3 and 4, with layer 4 being objects that will always appear on-top of the person. So, it appears that his player isn't a map object but an actor rendered separately from everything else.

Hmmm.

+1  A: 

To be honest, I would use a 2D array (for the x,y coordinates) containing a list ordered by height.

Assuming you do not need to rotate the landscape, you should be able to visit the array in a simple order, starting with the further away tiles and then drawing the closer ones. While drawing a tile, you would draw the lowest object there up to the highest (an empty list could mean draw the default ground colour).

Regarding the position of the player/character objects, I imagine they can only be in empty tiles? In which case special case the empty tile drawing code to check if someone is there and draw them after drawing the ground.

andrewmu