#139733 - ThousandKnives - Sun Sep 09, 2007 4:47 pm
Examing some GBA and SNES games on emulators I have noticed a recurring theme. That is, that the same background layer is frequently able to be drawn both above and behind the same sprite.
For example, an entire tree on an overhead map would be on a single layer. The character sprite could be both behind the top of the tree in one location and above the bottom of the tree in another location. Or there is a field background on one tile and the roof of a building on another. The character sprite is on top of the field but hidden by the roof as it moves "underneath".
Now, I know in both GBA and NDS that a background has to be given a specific drawing order in its entirety, and this can't be fiddled with on a tile-by-tile basis. At first I thought it might be a vcount deal, but sometimes it also happens during horizontal movements.
Does anyone know how this behavior is possible?
#139746 - tepples - Sun Sep 09, 2007 7:04 pm
Super NES text mode (mode 1) has three background layers, each with two Z (priority) levels. Each map entry has a bit for which Z level a tile appears in.
Game Boy Advance and Nintendo DS text mode (mode 0) has four layers, but each layer has only one Z level. If two layers with different Z levels are scrolled together, a game can set a tile's Z level by putting a tile in one layer or the other, with a transparent tile in the other layer. Some of the Super NES emulators put tiles with the "alternate Z" bit turned on into a separate layer.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#145656 - HyperHacker - Mon Nov 19, 2007 11:58 pm
Another way you might emulate this behaviour is to put a sprite with the same graphics overtop of the tiles in question, with a higher priority than the player sprite.
_________________
I'm a PSP hacker now, but I still <3 DS.
#151684 - sgeos - Mon Mar 03, 2008 7:20 am
HyperHacker wrote: |
Another way you might emulate this behaviour is to put a sprite with the same graphics overtop of the tiles in question, with a higher priority than the player sprite. |
Be careful not to do too much of this or you will "line over".
-Brendan
#151733 - Miked0801 - Tue Mar 04, 2008 12:53 am
Or burn an extra background for pass in front effects - what we ususally do.
#153874 - SevenString - Mon Apr 07, 2008 7:00 pm
In any BG layer where sprites may appear both in front of and behind elements, one way to deal with this is to have a per-tile map that contains a "z-depth" for each tile.
So your "tree" object might occupy a certain number of BG tiles, and you could easily mark those as having a certain "depth" in a seperate table, perhaps based on the bottom of the tree's "Y" coordinate? Given a "flat" ground in an othographic scene, the screen Y of the base of an object on that ground can easily serve as a measure of "depth" of that object in the scene.
Anyway, at runtime, if the sprite shares space with these tiles, you can simply compare the sprite's bottom Y coordinate (feet?) with the pre-stored depth of the tiles. If the sprite is lower in Y on-screen, set its priority to greater than that BG layer. If higher in Y on-screen, set its priority so that it appears behind the BG layer.
If you've marked BG tiles of different elements in this layer as having different depths, just watch your separation so you won't have any conflicts with sprites overlapping (in screen space) two different depths of elements at the same time in this one BG layer.
Finally, if you DO use an element's "bottom Y" as a measure of scene depth, remember that on the DS, the GREATER value is in front of the lesser. In most 3D work, depth is measured in terms of distance from the viewer, but using this Y-coordinate method, it's inverted with the larger value being "closer" to the viewer.
_________________
"Artificial Intelligence is no match for natural stupidity."