Draw multiple textures in a 2D scene

I’m trying to prototype a simple 2.5D scene and I draw it using Quads and spritesheets How to make spritesheet for JMonkey

I also set up camera for orthographic mode just like what Momoko_Fan is suggesting in his answer to How do I make my camera go in ortho mode? - #8 by Addez

I’d like to somehow be able to draw two textures on top of each other, e.g. one could be an npc sprite, the other is a helm that npc is wearing and the other is a sword npc is holding. Let’s assume that there could be a ton of sprites for npc, helms and swords so producing a singular texture for all combinations of these is impractical. One suggestion I saw on this forum was to use TextureAtlas and my concern is that it’d consume too many resources if I end up using this in a situation when there are a lot of texture combinations.

It seems that the easiest way to do this is to use multiple quads and lay them on top of each other using z coordinate increments to implement z-order.

I just wanted to confirm that it is indeed a way to go and no simpler or more optimal approach exists.

It seems a bit “hacky” to me that I need to increment z-coordinate as it may create an unintended effect of slight scaling of a topmost texture - albeit it seems that I shouldn’t worry too much about it as long as z coordinate increments are sufficiently small, e.g. 0.00001 or the like.

1 Like

In ortho mode, distance does not scale anything.

Sandwiching quads would be the normal way to do this. Whether each quad is using atlas-style UVs into one texture or different textures only matters if/when you want to batch things.

…but multiple quads is exactly how I’d do it in this case.

1 Like

Welcome to the community @stb !! Cool to see more new people around.
Hope you have fun with what you’re working on :face_holding_back_tears:

3 Likes

Thank you!

1 Like

Please have a look at the GitHub - Pesegato/MonkeySheet: Spritesheet library for jMonkeyEngine library. It’s made from the same author of the post and is usable right away :wink:
Also comes with extra features, so you might want to have a look at the code.

2 Likes

You can also have a look at my sprite library.
It has a different approach but does the job.
I have a few games on the playstore that uses it.

2 Likes

Awesome, thank you!

1 Like