Creating of sprite model

Good day!
I want to ask you recommendations about sprite models creation process.
First question:

  1. 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.

  2. 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.

1 Like

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?

Sorry, didn’t reply because don’t have the energy now to do the math… but the overall structure should look like:

  1. Convert 2D point on the screen (mouse position) into ray in the world.
  2. Calculate ray collision with your object.
  3. Convert collision coordinates into UV coordinates (coordinates on the texture of the object’s material).
  4. Get the pixel from the texture.

Unfortunately I don’t have a ready example on how to do that in 3D scene, recently I was doing that with TDrawableImage and it was absolutely trivial. First convert mouse position into position on the image (kinda UV coordinates) (1-3 are much simpler in the TDrawableImage case) and then if the UV coordinates are fine ask the texture if the pixel 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 RenderToImageBeginRenderToImageEnd), 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.

1 Like