Hello i want to developp a coloring game.
But when i color one object…all the objects behind or under it get the same color.
How are you breaking the picture up so you can colour each segment?
I’m going to assume you have them as separate objects. If so, When you colour in the object, I assume you are selecting the object under the cursor. If so, you’ll have to select the one with the highest Z order.
Checking for the highest z-order alone might not be enough. The issue is the object hit boxes.
If the hit boxes aren’t edited, they’re going to be rectangles in the size of the images.
You can see that in this image, the 2 hit boxes overlap in the center. If you try to pick an object in that region, both objects will get picked.
I think what you need to do is adjust the hit boxes.
Simple shapes like a triangle are easy.
But if the shapes aren’t convex, you’ll get an error. You can see how one point is sort of inside the shape. There are better, long explanations about convex vs concave. For more complex shapes you’ll need to use multiple polygons. I left a gap so you can clearly see that it’s multiple polygons .
You’ll never get a perfectly matching hitbox. You may still need to use pick the nearest object or the highest z-order. You can pick the highest z-order with help from the object picking extension.
Adding to Keith’s suggestion, make sure you use the condition “point inside object” for the hitboxes checks to work.
Otherwise, this condition “the cursor/touch is on an object” checks if the cursor is inside the object’s image boundaries ignoring the custom hitboxes.