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

Better solution for hitTestObject()?

Explorer ,
Nov 18, 2016 Nov 18, 2016

Why I get TRUE  if even circle dont tuching rectangle? Maby here is the other solution for this?

trace(circe.hitTestObject(rectangle));

FALSETRUE
false.jpgtrue.jpg
TOPICS
ActionScript
775
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
LEGEND ,
Nov 19, 2016 Nov 19, 2016

Every object has a bounding frame in the shape of a rectangle.  As soon as you enter into that frame you effectively hit the object, even if you cannot see it.

Go thru the following article and see if you can work thru a solution...

https://www.experts-exchange.com/articles/626/Flash-Collision-Detection-using-ActionScript-3-0.html

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
Explorer ,
Nov 19, 2016 Nov 19, 2016

OU thank you this is good lesson about this, SImple thing I want to use this:

stage.addEventListener(Event.ENTER_FRAME, hitTest);
function hitTest(event:Event)
{
if(rect1.hitTestPoint(mouseX,mouseY,true))
{
txt_hit.text = "HIT!";
}
else
{
txt_hit.text = "";
}
}

This is works with mouse but not with objects. I mean if mouse point is over then its true. But then I add the object always I get false.

stage.addEventListener(Event.ENTER_FRAME, hitTest);
function hitTest(event:Event)
{
if(object1.hitTestPoint(object2, true))
{
txt_hit.text = "HIT!";
}
else
{
txt_hit.text = "";
}
}

I have 45 objects (movieclips) around rotating wheel and one point (movieclip) then wheel stops I want to see points in txt_hit.text And I want something simple to do this.

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 ,
Nov 19, 2016 Nov 19, 2016
LATEST

hitTestPoint requires two parameters (an x and y) and has an optional boolean 3rd parameter.  ie, you can't use an object for the first parameter and a boolean for the 2nd.

i'm not sure what exactly you're trying to do but this will be closer:

if(object1.hitTestPoint(object2.x,object2.y, true))

and if you're trying to achieve a pixel-perfect hittest, use the bitmapdata hittest.

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