Good day!
I want to ask you recommendations about sprite models creation process.
First question:
This objects must be clickable. But also it will overlaps each other. It means, transparent parts must be “invisible” for mouse click, otherwise, when player will try to select something behind tree, he will pick tree. I can cut sprites in Blender, but it seems like bad approach, because lightweight sprite will became 3D model with many polygons.
I want to make shadows in future. I think to make parent TCastleTransform with trunk and parts of crown separately, as childs TCastleImageTransforms. Game will paint parts of object in dark-grey with transparency and gradient in depend of light direction…
And i need to make shadow spot on the ground, because real shadow of sprite seems not real.
Is it seems as a right plan or not?..
I made little sketch of tree and draw simple shadows, as I see them in game in future. Maybe I will add form to this dark spots or something else, but main idea is it.
Summarizing, at first step I must to make TCastleTransform, add TCastleImageTransforms with sprites and use it in scenes? And subsequently I can upgrade this with shadows without big problems.
I haven’t done 2D in CGE, but I think you could check the pixel color from the mouse click. If it is transparent then go to the next layer and check the color and so on.
As a understand, 2D and 3D it’s very close things in CGE.
You approach seems logical. For now I able to detect TCastleTransform under mouse, but I don’t know procedures for detect alpha channel of the current pixel.
And, if I will not pay attention to part of TCastleTransform with alpha = 100, is engine will ignore them to detect next TCastleTransform behind it automatically? How can I “pass through” the object, if it is transparent?
In your case you’ll need to do exactly the same, but the specific routines to call and math will be different, and unfortunately I can’t be more specific right now.
One more thing to note, sometimes textures may be available only on GPU memory and as such are hard/expensive-to-access. I.e. instead of TRGBAlphaImage for the TPixelTexture you’ll get nil - be prepared to handle this case somehow. I believe that this is rather an exception than a rule (happens if you construct the texture on GPU, e.g. through RenderToImageBegin…RenderToImageEnd), but I didn’t check it in a real-life scenario. I know that in Unity by default the texture is not accessible from code (i.e. rather a rule than an exception) and it needs a special setting to keep a copy in RAM.