2011-01-16 5 views
0

내 mc의 충돌이 두 번 발생할 때를 감지하기 위해 HitTestPoint를 실행하고 있지만 서로를 바로 통과 할 수 없도록하고 싶습니다. 누군가는 충돌이 발생할 때 움직이는 물체의 x, y 좌표를 찾은 다음 충돌이 발생할 때마다이 x, y 좌표로 해당 mc의 좌표를 업데이트 할 것을 제안했습니다. 나는 인터넷 검색을 해왔지만 비어있게되었다. 다음은 내 코드는 내가 당신은 거의가플래시 액션 스크립트 + 충돌시 x 및 y 좌표 얻기

private function __checkHit($evt:Event):void { 
    if (this.coin_mc.hitTestObject(target)) { 
    if (!hitting) { 
    coinSnd.play(); 
    count++; 
     total_count.text = String("$" + count); 
    hitting = !hitting; 
} 
    } else { 
    hitting = false; 
    } 
    if (mug_bounds.hitTestPoint(coin_mc.x,coin_mc.y, false)) 
    { 
     // do our in-circle check 
     if((mug_bounds.x - coin_mc.x) * 2 + (mug_bounds.y - coin_mc.y) * 2 <= (mug_bounds.width/2 + coin_mc.width/2) * 2) 
     { 
    **var coinX:Number = coin_mc.x; 
    var coinY:Number = coin_mc.y; 
         trace(coin_mc.x); 
    trace(coin_mc.y); 
    coin_mc.x = coinX; 
    coin_mc.y=coinY;** 
     } 
} 
else 
{ 
    trace("Didn't Hit Mug"); 
} 
} 

}

답변

0

을 시도 것. 원 - 서클 검사를 할 때 coin_mc 좌표를 설정해야합니다. 설정 한 값은 중지, 반송, 사라짐 등과 같은 상황에 따라 달라집니다. 예를 들어 아래 코드는 coin_mc가 접촉하는 지점에서 중지합니다.

if (mug_bounds.hitTestPoint(coin_mc.x,coin_mc.y, false)) 
{ 
    // do our in-circle check 
    if((mug_bounds.x - coin_mc.x) * 2 + (mug_bounds.y - coin_mc.y) * 2 <= (mug_bounds.width/2 + coin_mc.width/2) * 2) 
    { 
     //first find the angle between the two centre points 
     var diffX:Number =(coin_mc.x-mug_bounds.x); 
     var diffY:Number =(coin_mc.y-mug_bounds.y); 
     var radii:Number = mug_bounds.width/2 + coin_mc.width/2; 
     var angle:Number = Math.atan2(diffX,diffY) 

     // use trig to calculate the new x position so that the coin_mc isn't touching the mug 
     coin_mc.x = mug_bounds.x + radii*Math.sin(angle); 
     coin_mc.y = mug_bounds.y + radii*Math.cos(angle); 

    } 
} else { 
    trace("Didn't Hit Mug"); 
} 
관련 문제