multi layerd sprites

I want to be able to swap out certain elements on the fly with my main character, such as guns.

Id rather not have to create an entire set of sprite sheets for each weapon type so is there a way I can do this effectively in corona?

Ive thought of a couple of ways that might work. Overlay the sprite in a separate layer in photoshop so I can line the gun up just right in each frame, then export just that layer with the gun as a separate sprite sheet and play that on top of the player sprite. But my worry there is what if it got out of synch.

another idea is to just have one image file for the gun and dynamically rotate and translate its position relative to the player x,y position and rotation based on the current frame number.

So if in frame 2 the character is holding the gun slightly higher and at more of an upward angle I would just store that position in an array associated with frame 2 and adjust the gun image manually at each frame of the character sprite.

I have no idea if either of those ideas would work or if they would be the optimal way to do something like that in Corona. Anyone have any other ideas or experience with this? [import]uid: 128290 topic_id: 24489 reply_id: 324489[/import]

I’ve had experience doing swappable overlay sprites in another 2D engine and just want to caution that this approach can get complicated.

For example, let’s say your character is holding a gun. Is the gun layer rendered on top of or behind the character layer? You might think it’s obviously on top, but the hand of the character might need to be on top of the gun to look like he’s actually holding it. In this case the character is both in front of AND behind the gun. How do you decide which 2D order to render the layers?

Let’s say you have an animation sequence where the character spins around. On some frames of the animation the gun would be rendered on top of the character, on others the gun would be behind the character. You’d have to change the layer render order on the fly during the animation on the correct frames for it to look right.

The solution I used involved modeling and rendering the characters in Maya, a pricey 3D program that allowed me to separately render out each element while using other elements as masks for the alpha channel. Each element was assembled as a separate sprite sheet, and then finally each layer was rendered in the game in sync with the other layers. It worked but it was a time consuming, labor intensive, and expensive process.

It may in fact be much easier to do what you are trying to avoid and simply create a separate spritesheet of the character for each weapon type. If you are hand drawing the sprites then this can also get time consuming the more characters and weapons you have. The advantage is you don’t have to do any layer compositing at all and will avoid problems keeping layers in sync.

If you use a tool like Flash to generate your sprite frames you can use it’s layering and layer visibility features so you only have to draw the character once and then re-render animation frames each time with a different weapon visible.
[import]uid: 9422 topic_id: 24489 reply_id: 99122[/import]