Skip to main content
November 20, 2011
Answered

hitTestPoint not recognizing full shape

  • November 20, 2011
  • 1 reply
  • 580 views

Hey guys, thanks in advance for help.  Anyone know why "hitTestPoint(character.x, character,y, true)" would be hit testing off the origin point in the center of the character, and not the whole shape??

This is my code from my document class.  There's a custom splat class in there, but don't worry about that.  This code is inside 2(1 nested) for loops.

function hitTestBalls(e:Event) {

                       

                              for (var i = ballArray.length - 1; i >= 0; i--) {

                                        for (var m = MonsterArray.length - 1; m >= 0; m--) {

if ((ballArray.hitTestPoint(MonsterArray.x,MonsterArray.y, true)) && (MonsterArray.MouthClosed == true)) {

                                                            trace("219");

                                                            var splat:Splat=new Splat(ballArray.currentFrame*10,ballArray.x,ballArray.y);

                                                            addChild(splat);

                                                  }

                                                  if (ballArray.hitTestObject(MonsterArray.HitTester)||ballArray.x>stage.stageWidth||ballArray.y>420) {

                                                            trace("217");

                                                            if (ballArray.y>420) {

                                                                      var splat2:Splat=new Splat(ballArray.currentFrame*10,ballArray.x,ballArray.y);

                                                                      addChild(splat2);

                                                            }

                                                            ballArray.updateTimer.stop();

                                                            ballArray.updateTimer=null;

                                                            ballArray.parent.removeChild(ballArray);

                                                            ballArray.splice(i,1);

                                                  }

                                        }

                              }

                              updateScore();

                    }

This topic has been closed for replies.
Correct answer kglad

"hitTestPoint(character.x, character,y, true)" tests against character's registration point which can be located anywhere depending on your setup.  that reg point could be nowhere close to any pixels that you see that comprise character's shape.

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
November 22, 2011

"hitTestPoint(character.x, character,y, true)" tests against character's registration point which can be located anywhere depending on your setup.  that reg point could be nowhere close to any pixels that you see that comprise character's shape.

November 22, 2011

Makes sense, sometimes I overlook the obvious answers, yet more complicated things don't give me problems haha.

Thanks again, you solved both my questions today!

have a good one!

kglad
Community Expert
Community Expert
November 22, 2011

you're welcome.