Skip to main content
Participant
March 12, 2013
Answered

hitTestObject checking collision with pattern

  • March 12, 2013
  • 1 reply
  • 829 views

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

This topic has been closed for replies.
Correct answer kglad

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.

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
March 12, 2013

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.

PaulQmmQAuthor
Participant
March 13, 2013

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.

kglad
Community Expert
Community Expert
March 13, 2013

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.