Members - Reputation: 326
Posted 28 July 2012 - 07:45 AM
Moderators - Reputation: 10288
Posted 28 July 2012 - 09:08 AM
To draw this, you could draw the turtle dude first, then the axe on top:
However, you can't simply specify the stacking order once per character, because depending on the orientation of the character, the rendering order might instead be Axe first, Turtledude second, as in this orientation:
So it requires being able to specify a drawing order per frame (since even within a given animation sequence for a given facing direction, the drawing order could possibly change) and that requires a quite time-consuming process. It also requires specially constructed tools for processing the sprite pieces. In the above example, the axe sprite is not exactly correct. I performed the render as turtle first and axe second, each piece separate, but if you draw the frame as specified, then the axe will simply be drawn over the top of the turtle sprite and the part of the handle that should be obscured by the turtle's hand where the hand grips the shaft will not be obscured:
So you need to write a tool of some sort that can take the separate renders and process them so that the pieces fit correctly. One possible way of doing this is to export a depth map during your rendering pipeline and use the depth map to determine which pixels of the axe will be visible when drawn, and snip out the hidden ones. You could also conceivably use this depth map to determine the drawing order as well.
It gets even more complicated when you add more pieces of equipment. Whether you hand-draw things or render them, it still means you are in for a great deal of grunt work. The task will be made vastly simpler if you build the proper tools to help with all of this. Doing it all by hand, for hundreds of frames per character, dozens of characters per game, is just not feasible. You need tools to help reduce the workload.
Another problem with this system is the fact that texture memory usage can explode. You will want to pack your sprites as tightly as possible, and even still you are going to eat a chunk of memory. Consider the above turtle dude. Say you have 8 facing directions for an isometric; and 8 is considered low, especially for a player character. 16 or even 32 would be more appropriate, at least for a player character. And say a typical animation set for the character includes 50 frames total. This includes all animations for walking, idling, attacking, casting spells, etc... 50 is a good guess, though more detailed characters would want more. 50 frames x 8 directions equals 400 frames. In a naive non-packing implementation, 400 frames @ 128x128x4 is equal to 25MB of data. And that's just for the base sprite. In a non-packing arrangement (ie, the sprite rectangles are not snipped and packed but are left as full frames) every piece of equipment you add will add another 25MB to the total. The axe, for example, would need to be rendered 50 frames in 8 facing directions just as the turtledude base sprite. If he's wearing a hat, that's more renders. It adds up quickly.
Proper sprite packing can mitigate this quite a bit. The axe sprite above is mostly empty space. Your animation tool can "snip" these sprites and pack them in a more dense arrangement to save space. My personal experiments show an average size reduction of 1/3 to 1/5, so the axe sprite set might take up 5 to 8MB instead of the full 25MB. Some very small sprites will be even better reduction, but even so it adds up very fast. It is a lot of texture memory to juggle.
Once again, the proper tool will make the job easier. I don't personally know of any pre-existing solution (outside of my own personal tools, which I don't make available) so you'll probably have to build your own.
Now, here is a little secret. There is one change that you can make, that will very nearly make all of this complexity go away. No fiddling with drawing orders, no farting around with sprite editing and processing and rectangle packing and worrying about exploding texture memory usage. And that change is this: use fully 3D characters.
It is not too hard to use full 3D characters, even if the backgrounds and landscapes remain 2D. You do have to build an abstraction where the landscape is drawn in a 3D fashion, but you can continue to use pre-rendered 2D sprites for the landscape pieces. But if you draw your character as a full 3D character, all of the above complexity goes away. Drawing order? Just draw the pieces, and let the Z buffer sort it out. Texture memory usage? A single small texture per weapon or equipment piece, plus a small geometry buffer. No extra memory required for the various facing directions. You simply attach 3D models to a character skeleton, and let the rendering process handle making it all look right.
I highly recommend that you go the 3D route if you plan on any sort of complexity in your equipment system. On modern hardware, there really is no reason not to. The results can be very nearly as good as pre-rendered (although you do miss out on some neat tricks, such as anti-aliased sprites with smooth blending against the background) but a good shader and post-processing chain can mitigate a lot of what you miss out on from the switch away from pre-rendered sprites. You avoid the necessity of having to write a tool to process sprites, you save yourself a ton of time from pre-rendering all the various equipment models and tweaking drawing orders, etc... This is the reason that most existing 2D games that use paper doll systems either stick to very simple characters, or drastically limit the equipment choices available. (Look again at Diablo 2. There were only a very few actual different armor and weapon models, compared to the number of weapons and armors actually available to you.) Compare that to the number of equipment options in, say, World of Warcraft. (There are literally hundreds, if not thousands, of equipment models per character base type.) You just couldn't manage that level of complexity using traditional 2D sprite methods; the memory usage alone would eat most graphics cards alive.
Members - Reputation: 485
Posted 28 July 2012 - 09:55 AM
Let’s say this is Photoshop and everything is done in layers. Take particular animation frame and have it as the bottom layer. Create a new layer for each piece or set of equipment and draw on top of the animation frame. Create a new sprite sheet for the item only. Select the layer of the worn item and copy and paste it into same index position as animation frame. While in the game, render the character's sprite sheet first then all the separate equipment sprite sheets in the order of feet going up. That way something like a cape gets rendered on top of boots.
The problem with this is the armor and equipment is specific to the character. This is not a problem if the main character is the only character. Unless all the characters are the same size and have identical movements, you could possibly reuse the equipment animation. Otherwise, repeat the process for all the other characters.
I'm slow at typing
JTippetts explained it better.
Edited by Neometron, 28 July 2012 - 09:57 AM.