Hi friends!
Let’s say I have 1 to x displayObjects that i’m generated and dropping onto the screen at random. I then addBody() to them to make them physics objects.
So I’ve got this game that is raining objects, and each of those objects have some properties (let’s say color) that I’ve added to them at random.
On a collision I need to:
1. know what objects each of the other objects are already touching
2. recursively perform an operation on these objects
We could take a game like Bejeweled or many of the clones as an example. So if I’m dropping objects onto a screen and they have a random color assigned to them, on collision I’d like to know what objects each object is touching (like a chain), and then compare their properties. Matching color objects would then be destroyed.
Searching the forums I couldn’t find a post specific to my needs (some were close, like telling me if objects were in the space surrounding - but not which objects…), so I tried a homegrown solution of:
on collision store the object I collided with and it’s property into a local object property.
on event.phase “ended”, delete said property.
But I’m finding there is a condition where, if my objects come into contact at multiple points, the “ended” phase doesn’t happen at the right time (it sometimes happens too late). At any rate, there seem to be a bunch of things wrong with this implementation.
Is there a better, more standard way to approach my problem? Have I missed some idiom or library that could help me here? What approach might you take for knowing what objects are touching what objects, and selectively performing operations on all connected objects?
I appreciate the help. Thanks for taking the time to read my post.