#168713 - sylus101 - Sat May 16, 2009 5:26 pm
Hi Folks,
I recently stopped using PALib in favor of learning to use libnds directly. PALib had an "extended" priority system of some kind that allowed sprites with the same bg layer priority to change priority in some way. The only possibly way I can see this working is by changing the actual OAM entry number for a particular sprite as lower (0, 1 ,etc...) numbers are on top of higher ones (126, 127, etc..).
I have need in a new project of a way to do this. Basically, enemy AI is going to have them changing who is in front of who pretty often. Is there some other method I'm not aware of? Is a dynamic method of changing OAM id's the only way?
#168718 - gmiller - Sat May 16, 2009 11:38 pm
The sprite priority in OAM for the GBA is only 2 bits so you only have the values of 0 - 3. The sprites at the same priority are ordered in display layers based on the sprite number (so for example sprite 0 will show in front of any other sprite of the same priority. If a tile background and a sprite have the same priority then the sprite will show in front. So to have a sprite go behind a background the sprite must have a lower priority (0 is highest prioriy and 3 the lowest). The extensions for NDS multiple banks are unknown to me so others would have to comment.
#168719 - gmiller - Sat May 16, 2009 11:40 pm
For the who is in front you could load your OAM copy in the correct order and then write that to the OAM area.
#168733 - sverx - Mon May 18, 2009 10:57 am
sylus101 wrote: |
The only possibly way I can see this working is by changing the actual OAM entry number for a particular sprite as lower (0, 1 ,etc...) numbers are on top of higher ones (126, 127, etc..). |
Yes, actually -on NDS- the drawing order comes from a 9 bit value built using the OAM index (lower 7 bits) and the priority bits (two) left shifted by 7 so, in short, two objects with the same priority will overlap according to their OAM index...
#168755 - sylus101 - Wed May 20, 2009 3:45 pm
Thanks guys.
I worked out a temporary system using 192 minus the sum of the sprites y coordinate and it's pixel height (and a check to make sure it's not already in use). This works great for my current project as I only need the bottom half of the screen... I'll possibly revisit it later to come up with a more portable system.
Thanks everyone!
#169714 - keldon - Fri Jul 31, 2009 12:20 am
It's late now, but I'll tell you how I achieve this on Saturday.
Edit: As promised I will tell you how I achieve it - although I just realized that I did by the order of requests to the OAM allocator, so it's not exactly what you want. However you could achieve this with <a> unique OAM indexes, or <b> by transferring temporary OAM entries to the OAM table each frame based on the priorities. The former approach requires unique indexes, whilst the latter approach allows for more than one OAM entry sharing the same pseudo priority. And std::set (ordered by the priority, then the temporary OAM address) could be used to order the OAM entries based on their priorities.
Hope that helps!