Changing the Render Order
#1 Members - Reputation: 163
Posted 14 November 2012 - 03:10 PM
I am making an isometric game in 2D and am having some difficulty in coming up with a solution to my current problem.
If I have lots of little characters (just an example) running around the screen, I want to know what order to render those sprites in. I already know that I can do this simply by knowing each of the characters Y coordinate (If the Y coordinate is lower than one sprite, then it should be rendered in front).
I have already written a sample program that gives the illusion of a ball orbiting around a pole. Trouble is, if I have lots more than just two sprites - for example 20 sprites... it becomes a little more complicated.
I am struggling because obviously, a web of IF statements will not suffice. I would like to know if there is a common method that people may use in this situation? And, lets say for example I was able to get all the objects Y pos and order some kind of virtual Z buffer array that will help me order the rendering, how would I go about this for those objects already contained in a vector (A vector containing 10 generic automated characters for example).
Any thoughts on this? (That is, if I have explained myself correctly). I am using Direct3D 9.0 and C++ although I am sure languages and library's do not really come in to this much.
Thanks
Chris
#2 Members - Reputation: 440
Posted 14 November 2012 - 03:39 PM
Hi folks,
I am making an isometric game in 2D and am having some difficulty in coming up with a solution to my current problem.
If I have lots of little characters (just an example) running around the screen, I want to know what order to render those sprites in. I already know that I can do this simply by knowing each of the characters Y coordinate (If the Y coordinate is lower than one sprite, then it should be rendered in front).
I have already written a sample program that gives the illusion of a ball orbiting around a pole. Trouble is, if I have lots more than just two sprites - for example 20 sprites... it becomes a little more complicated.
I am struggling because obviously, a web of IF statements will not suffice. I would like to know if there is a common method that people may use in this situation? And, lets say for example I was able to get all the objects Y pos and order some kind of virtual Z buffer array that will help me order the rendering, how would I go about this for those objects already contained in a vector (A vector containing 10 generic automated characters for example).
Any thoughts on this? (That is, if I have explained myself correctly). I am using Direct3D 9.0 and C++ although I am sure languages and library's do not really come in to this much.
Thanks
Chris
There are two ways I do isometric rendering.
One is kind of slow and relatively complicated for a new dev. One way I do isometric rendering is to give each pixel a number representing it's distance from the virtual camera. So, you start by drawing a tree which has a closeness of it's y value. if the player is in front of the tree then it's y value must be bigger.
Instead of using if statements I used an 2D array of integers which each represent a pixel on the screen. When you draw an image on the screen it writes that corresponding integer in the array to the y value of the image. If another image is trying to be drawn over another image then the image's y value has to be bigger than the one on the screen. I'm finding it hard to explain.
Another method would be to have tiles on the screen then add the objects onto the tiles then when the tile is rendered isometrically then the object is rendered too.
#3 Members - Reputation: 478
Posted 14 November 2012 - 03:55 PM
1) Place all the objects you want to render in a list.
2) Sort this list by the Y axis (biggest Y will be the first of the list, lowest Y will be the last one).
3) For each object in the list, render it.
Hope it helps.
http://16bitsflag.blogspot.com.br/
#4 Members - Reputation: 163
Posted 14 November 2012 - 03:56 PM
And unfortunately, I do not fully understand what you were trying to explain for your other method but thanks anyway!
I think I will look at adding tiles to the screen unless anyone else has another method that may fit better?
#5 Members - Reputation: 163
Posted 14 November 2012 - 04:01 PM
#6 Members - Reputation: 478
Posted 14 November 2012 - 05:25 PM
If it is a STL vector (the one that comes by default), you should use the sort function from algorithm. Here is some documentation:
http://www.cplusplus.com/reference/algorithm/sort/
On the rendering, I don't know how Direct3D works, so I can't really help. I
If you render every object every frame, just render every element of your objects vector and you should be fine.
EDIT: Didn't see that you said you are using CPP, corrected some info.
Edited by KnolanCross, 14 November 2012 - 05:27 PM.
http://16bitsflag.blogspot.com.br/






