Sign in to follow this  
hubblewubble

2d tile Occlusion in xna

Recommended Posts

Hello, I decided to follow Nick Gravelyn's tile engine tutorials for my introduction into XNA and I found them to be quite helpful. I am a little unsure on how to implement occlusion though. I have searched but most of the items I saw said to either use Z (for 3d) or use Y. I can't use Y either though. If I have multiple tile layers, and I want the bottom ones to draw underneath whereas a few top ones should draw above the player. The tiles will still be from 0,0 to 31,31 etc though so Y wouldn't work. I thought about adding another layer similar to a collision layer that would store the cells that should draw 'above' the player. I would also store layer ID's that should take this into effect so the base layers will still be drawn (for transparency). Is this what I'm supposed to do or is there some other way because it seems a little excessive. I've been thinking about this for a few days now and this is still the only thing I have come up with. Also if I decided to do a Mario where instead of just not drawing some portions of higher layers, I draw them overtop of the sprite, how would I need to handle my drawing? I currently just loop through all the layers in the map and draw them and then I go through all the sprites and draw them.

Share this post


Link to post
Share on other sites
Your thought about another layer seems to be logical to me. Using the Z to determine drawing order (is that called Z-ordering or something, not sure), I think could be used in a 2-d sense, though I am not sure how to implement it.

If you create a derived layer class (for things you wish to draw on top of your sprites) from your original layer, your drawing would still be the same, loop the original layers, draw the sprites, then draw the new derived class (that way they are drawn last on top of everything else). I know that does not sound like the most efficient way to do it, although I myself am at a loss on another way (though I am still beginning at game development).

Hope that makes some sense, or helps some, or maybe gets someone more knowledgeable to help us both out....

Shawn

Edit - One quick edit, and I am not sure how you are doing this. But, I believe in one of Nick's vids, he does recommend that each layer has its own SpriteBatch begin method. Otherwise ordering of the drawing can get messed up since the textures would be batched together for efficiency.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this