I assumed this was relatively simple, but as it turned out, its not. Now I ask that before you reply, I fully understand what is says in the manual, and I am not some noob who needs the basics explained to me, I am referring to rendering the textures on the device. I am also fully aware that the more recent object gets drawn first if they are equal.
I am running into a few minor issues with Z coordinates for this XNA/IronRuby engine I am making. The only place I really see this problem is with the default battle system. Here is what it appears as:
As you can see, everything appears fine except for the enemy being placed above the @actor_command_window.
I have tried a couple different ways of factoring sprite.z and viewport.z, by simply adding them together as one way. I was incorrect in this assumption, this is the way that I have been calculating, but have run into problems here, as the screenshot demonstrates. The enemy sprites have a Z of 304 on their own viewport that has a Z of 0. The @actor_command_window has a Z of 100 (inherited from Window_Base) without a viewport, so 0 would be added to it to get it's final depth. That makes a final tally of the enemy sprites having a Z of 304, and the @actor_command_window having a Z of 100. This is the reason the enemy sprites are on top, so simply adding them is not the correct answer.
I assumed next that drawing was ordered by the viewports, and the sprite's z only pertained to that particular viewport. For example, if there are two sprites, sprite A with z of 10, and sprite B with z of 0, but sprite B's viewport.z was higher than sprite A's viewport.z, sprite B would still appear on top. I was incorrect in this assumption as well, which can be demonstrated with this little snippet in RMXP.
viewport = Viewport.new(0, 0, 640, 480)
viewport.z = 50
sprite_A = Sprite.new(viewport)
sprite_A.z = 0
sprite_A.bitmap = RPG::Cache.character('001-Fighter01', 0)
sprite_B = Sprite.new
sprite_B.bitmap = RPG::Cache.character('002-Fighter02', 0)
sprite_B.z = 100
If that logic was correct, the second sprite should be under the first, since it does not have a viewport, and the first sprite's viewport has a Z of 50.
So I began testing how they relate within RMXP, and I am just getting more confused.
viewport = Viewport.new(0, 0, 640, 480)
viewport.z = 50
sprite_A = Sprite.new(viewport)
sprite_A.z = 100
sprite_A.bitmap = RPG::Cache.character('001-Fighter01', 0)
sprite_B = Sprite.new
sprite_B.bitmap = RPG::Cache.character('002-Fighter02', 0)
sprite_B.z = 100
No matter which order the sprites are created in, this causes the second sprite to always be on top, even though it does not have a viewport, and the first one does with a Z of 50, and both sprite's have the same Z value.
Now, lets change the first sprites viewport to 100, and change nothing else.
viewport = Viewport.new(0, 0, 640, 480)
viewport.z = 100
sprite_A = Sprite.new(viewport)
sprite_A.z = 100
sprite_A.bitmap = RPG::Cache.character('001-Fighter01', 0)
sprite_B = Sprite.new
sprite_B.bitmap = RPG::Cache.character('002-Fighter02', 0)
sprite_B.z = 100
The second sprite appears on top, but only because it was created more recently, as you can test by changing the creation order. This leads me to believe that the viewport's Z doesn't do a damn thing, since it appears it wasn't even factored in to the drawing, and only the order the sprites were created in.
So let's test this theory, I will increase the viewport's Z very high, and lower the sprite's Z.
viewport = Viewport.new(0, 0, 640, 480)
viewport.z = 1000
sprite_A = Sprite.new(viewport)
sprite_A.z = 50
sprite_A.bitmap = RPG::Cache.character('001-Fighter01', 0)
sprite_B = Sprite.new
sprite_B.bitmap = RPG::Cache.character('002-Fighter02', 0)
sprite_B.z = 100
Oh wait, nope, that's not it, that makes the first sprite, with a lower Z, higher than the second sprite, simply because it's viewport was higher. But that didn't work earlier when we tried it with this snippet:
viewport = Viewport.new(0, 0, 640, 480)
viewport.z = 100
sprite_A = Sprite.new(viewport)
sprite_A.z = 100
sprite_A.bitmap = RPG::Cache.character('001-Fighter01', 0)
sprite_B = Sprite.new
sprite_B.bitmap = RPG::Cache.character('002-Fighter02', 0)
sprite_B.z = 100
So what the fuck? Does it simply take the higher of the two between the a sprite's viewport's Z, and it's own Z, then use that? Or is there some magical, undocumented Z value added when a sprite does not have a viewport?
I don't know, maybe I am just getting burned out and need to take a break so I can step back and see this more clearly, but this has been my issue for the all of yesterday and today, and I have not gotten anywhere on it.