2014-09-15 8 views
0

그래서 기본적으로 화면 경계에없는 시체를 파괴하려고 할 때 오류가 발생합니다.Libgdx 여러 몸체를 파괴

Maingame 루프 클래스 :

Array<Body> bodies = new Array<Body>(world.getBodyCount()); 
    world.getBodies(bodies); 
    for (Body body : bodies) { 
     check = 0; 
     if (BodyUtils.bodyIsEnemy(body)){ 
      update(body); 
      check = 1; 
     } 
     if (BodyUtils.bodyIsBullet(body) && check == 0){ 
      update1(body); 
      check = 0; 
     } 
    } 

private void update(Body body) { 
    if (!BodyUtils.bodyInBounds(body)) { 
     if (BodyUtils.bodyIsEnemy(body) && !player.isHit()) { 
      createEnemy(); 
     } 
     world.destroyBody(body); 
    } 
} 

private void update1(Body body) { 
    if (!BodyUtils.bulletInBounds(body)) 
     world.destroyBody(body); 
} 

다른 클래스 :

또한 내 한 종류의 몸은 다른 ​​종류의기구가 파괴 될 때 이상한 행동을하기 시작 여기에 코드 샘플은 (예를 들어 총알이 뒤로 이동하기 시작)
public static boolean bodyInBounds(Body body) { 
     UserData userData = (UserData) body.getUserData(); 
     switch (userData.getUserDataType()) { 
     case ENEMY: 
      return body.getPosition().x + userData.getWidth()/2 > 0; 
     } 
     return true; 
    } 

    public static boolean bulletInBounds(Body body) { 
     UserData userData = (UserData) body.getUserData(); 
     switch (userData.getUserDataType()) { 
     case BULLET: 
      return body.getPosition().x + userData.getWidth() < 20; 
     } 
     return true; 
    } 
+0

'world.step'이 실행되는 동안이 작업을 수행하고 있습니까? 예를 들어 콜백에서 그 의미는 무엇입니까? – noone

+0

예, 세계 단계는 동일한 방법으로 실행되고 있습니다 (루프 – Rimwis

+0

). 동일한 방법으로 실행 중이거나 병렬로 실행 중입니까? – noone

답변

0

world.destroyBody (body) 메소드 다음에 배치 된 createEnemy() 메소드가 수정되었습니다.