Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

hitTestObject checking collision with pattern

Community Beginner ,
Mar 12, 2013 Mar 12, 2013

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

TOPICS
ActionScript
789
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 12, 2013 Mar 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.

Translate
Community Expert ,
Mar 12, 2013 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 13, 2013 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 13, 2013 Mar 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 18, 2013 Mar 18, 2013

Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 18, 2013 Mar 18, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines