Based on my knowledge, your approach with raycasting to detect attachments is on the right track! Here are some suggestions for implementing this feature:
Your Raycast Approach:
Yes, this is a valid starting point. You can iterate through visible attachments in draw order and check if your brush position intersects with their bounds. For each attachment, you can get its bounds using the attachment's properties (x, y, width, height).
Alternative and Complementary Approaches:
Use a separate damage/scribble mask texture:
Instead of modifying the original atlas texture directly, create a lower-resolution grayscale mask texture. This mask can then be used as a blend factor between the normal texture and a "scribbled" version. This approach:
- Is more performant (lower resolution)
- Preserves the original atlas
- Allows for easier reset/cleanup
Mesh-based approach:
If your face attachments use meshes, you could overlay a separate mesh attachment with your scribble texture on top of the face. This would be easier to manage and wouldn't require complex texture manipulation.
Pre-defined scribble variations:
The simplest solution would be to prepare 3-4 pre-made "scribbled face" variations in Spine and swap attachments when the player defeats an enemy. You could either:
- Switch the attachment at the slot
- Overlay a damage/scribble attachment on top
Important Considerations:
- Never modify the original atlas texture - always work with a copy, otherwise all skeleton instances will be affected
- Consider the performance impact of texture modifications during gameplay
- If you're instantiating multiple enemies, texture operations per instance could add up
For a feature that doesn't require very high performance or visual quality, starting with pre-made scribble variations as overlays would be the easiest to implement and maintain!