I've got a little problem, I've been wandering around the forum and wiki for quite some time but I didn't find anything that helped me.
The thing is simple, I've got two textured quads, both having transparency, and I'd like them to be transparent with each other when they collide. (I'm using JME to make a 2D renderer, because I also will be using 3D in another renderer. Long story short, I want to achieve that with JME, for practical reasons)
So the root node is in QUEUE_ORTHO render queue mode, and my childs have different Z-Orders.
(cf the attached image, the chocobo is above a chest, and you can barely see that the chest is occluded by the chocobo background.)
I know JME hasn't been built to support 2D games, but what if someone wants to add transparency in his HUD, using multiple "layers"?
Ok. So I guess the answer is "Use Slick or another 2D game engine if you want to do that"? ^^
- make sure the chocobo texture has transparency
- add a blendstate
- (draw the chocobo after the chest, meaning add it to the rootnode later)
What I do actually is :
- Create a node with a chocobo texture (comes from a GIF with transparency, attached)
- Create a node with a chest texture (comes from a PNG with transparency, attached)
Both of these nodes use this code :
textureState being the TextureState having the texture loaded from the gif/png.
transparencyState being a state created only once and used by every sprite having transparency (maybe this is the error, I didn't try to create 2 different states, can't try it here). This state is created like this (copied/pasted from a JME tutorial):
transparencyState = renderer.getRenderer().createBlendState();
So this creates 2 nodes with transparent textures on them. These nodes are directly rattached to the rootNode. After that, I create 2 Quads:
- One chocobo, I attach it to the corresponding node (so it inherits the textureStates) and set a Z-Order of 1:
Quad sprite = new Quad("Entity #"+id, width, height);
- One chest, with the exact same code but with a Z-Order of 2.
The transparency works for the background color (we see a black background for both of my images instead of the white BG if I don't use the transparencyState), but not for the collisions, as shown above).
maybe this is the error, I didn't try to create 2 different states, can't try it here
Tested, still not working right.
Well… It’s solved!
I tried modifying the blender state, because it was the only part I didn’t try to change, so I changed the function from substract to add (transparencyState.setBlendEquation(BlendState.BlendEquation.Add);) and then it works!
I did substract because of this wiki tutorial, without any modifications.