|
Layer order of sprite rendering |
alexius wronka
Member #15,571
April 2014
|
Good Morning everyone, I'm currently having a great time creating a 2D overhead Zelda esq game using C++ and Allegro 5. However my game is more of a Beyond Oasis perspective then a Zelda Perspective and objects need to appear behind other objects when they have a higher y position and above when they have a lower y position. I have gotten it to work with one object on the other. I created and if/else depending on the y coordinate of the one object. How would I go about creating this function using every moving object in the game. How can I define the two y variables within the class to create a correct draw order? Right now I have all characters except the user character inherit all x,y coordinates from a base class. What do I need to do so that I can have two characters who inherit the same x,y to interact? |
Slartibartfast
Member #8,789
June 2007
|
Presumably you are going over all characters in order to draw them - why don't you sort them in ascending y order before drawing? If you are using an STL container then you can use std::sort from #include <algorithm> to quickly sort your array of characters. Also, the correct forum for programming questions is the Programming Questions forum, the Allegro Development forum is for the development of Allegro itself. ---- |
beoran
Member #12,636
March 2011
|
Yes, first filter (by visibility) and then sort your sprite data. In plain C you'd probably use qsort() to do this. My game engine does exactly that, since I'm also planing to make a top-down RPG. If you're interested check it out here: |
|