문제

I got a media clip called point with multiple child graphics. When my char hit a child i want to get the name or the child number of that graphic

if (point.hitTestPoint(char.x + 20,char.y + 30,true)){
    //name of child hit
}

Is this possible?

도움이 되었습니까?

해결책

You can brute this by hit testing the children in the container. Something like...

if (point.hitTestPoint(char.x + 20,char.y + 30)) {
  for(var n:int = 0; n < point.numChildren; n++) {
    if(point.getChildAt(n).hitTestPoint(char.x + 20,char.y + 30,true)) {
      // Do something. Store name, whatever
      break;
    }
  }
}

This isn't the most optimal method, but is simple and matches how you are currently doing it. If you are doing this for a game at high speed, then you would want to look into some kind of spatial partitioning to optimise your test.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top