Copy link to clipboard
Copied
I've got an enter frame event that checks collision between mouse cursor and objects on the screen. The problem. Every object has a name, however I want to detect collisions between the cursor and objects with a pattern name.
For example, on the screen there are five objects called
XObj1
AObj2
XObj3
XObj4
AObj5
I want to check collision only between mouse cursor and every object that starts with X or A.
The solution I had doesn't work out the way I expected because it runs a loop and returns array with an index of these objects. I would like to have a straightforward approach like
MouseCursor.hitTestObject(stage.getChildByName(Pattern));
But I don't know if it's possible.
Thanks in advance
you need to repeatedly loop through each object that needs a hittest or put all those objects in a common parent that contains no other child and repeatedly check a hittest with the parent.
Copy link to clipboard
Copied
you need to repeatedly loop through each object that needs a hittest or put all those objects in a common parent that contains no other child and repeatedly check a hittest with the parent.
Copy link to clipboard
Copied
It seems tough though.
So, is it possible to have more than one object with the same name?
A sprite object in an array
Objects_Array[0].name = Omega;
Objects_Array[1].name = Omega;
Objects_Array[2].name = Omega;
Objects_Array[3].name = Omega;
?
So I would check collision among many objects easily.
Copy link to clipboard
Copied
yes, it's possible but you don't want to name different objects with the same name.
again, put all the objects in an array and loop through the array each time you check your hittest or reparent the objects so they all have the same parent.
Copy link to clipboard
Copied
Thanks!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now