Sign in to follow this  
doutmost

How to deal with this?

Recommended Posts

Suppose I have two squares, square 1 and square 2, 1 is behind 2, how can I draw them correctly as in the real world that I can only the part of square 1 not to be hiden by squre 2? Thanks for any advice.

Share this post


Link to post
Share on other sites
Quote:
Original post by Frogget
Draw square 1 first, then square 2 over top of it.


I think what Frogget has suggested is the best solution -- just draw the squares in depth order so the one to be on the bottom is drawn first and the square to be on the top is drawn second.

Share this post


Link to post
Share on other sites
if you are using perspective view then opengl will do this automatically if depth testing is enabled ... if you are using ortho view you can also enable depth testing and give your objcts "z values" ... or if you want to do this manually, you can use a sorting algorithm and sort your list of objects so that when you render them they display furthest to nearest.

Share this post


Link to post
Share on other sites
what kind of game are you making ? im assuming its 2d... is a side scroller or ISO or top down game or what?

anyway, most likely you have to sort your objects by their Y axis, so that things on top will be drawn first. this way, if character A is standing above character B, character A is drawn first, which would make B's upper body cover up A's lower body, making it look like hes standing in front of him.

the way i do this is pretty simple. ill go into more details once you give more info though. the gist of it is i make a master class which all things needing sorting derive from, i store them all in a std::list, i overload the < operator then i just .sort() the list each frame then render.

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