2009-05-19 3 views
8

Box2D로 끝없는 포장 세계를 만들 필요가 있습니다. 모든 객체의 X 좌표는 0 < X < 1000입니다. 물건을 순간 이동하면서 게임을 해봤지만 더 좋은 방법이있는 것처럼 느껴집니다 - 어떤 생각입니까? 어떤 객체 (또는 연결된 객체의 체인)도 화면의 너비보다 작은 약 50 이상의 X 스팬을 갖습니다.Box2D에서 포장 세계를 만드는 방법

카메라는 한 번에 세계의 일부만 볼 수 있습니다 (약 5 % 너비, 100 % 높이 - 세계는 약 30 높이 1000 와이드).

건배.

+1

여기에 플래시가 있습니까? 사람들이 쉽게 질문을 찾을 수 있도록 적절한 언어 태그를 추가하십시오. –

+0

Box2D는 2D 게임이나 시뮬레이션 개발을위한 OpenGL 백엔드가있는 C++ 라이브러리입니다. –

+0

저는 실제로 C# 포트를 사용하고 있지만 솔루션이 특정 언어 일 것이라고는 생각하지 않습니다. –

답변

0

나는 다음을 구현했습니다. 이는 결코 이상적이지는 않지만 제 목적에 부합합니다. 많은 제약이 있으며 실제 랩핑이 아니지만 충분합니다.

public void Wrap() 
    { 
     float tp = 0; 

     float sx = ship.GetPosition().X;   // the player controls this ship object with the joypad 

     if (sx >= Landscape.LandscapeWidth())  // Landscape has overhang so camera can go beyond the end of the world a bit 
     { 
      tp = -Landscape.LandscapeWidth(); 
     } 
     else if (sx < 0) 
     { 
      tp = Landscape.LandscapeWidth(); 
     } 

     if (tp != 0) 
     { 
      ship.Teleport(tp, 0);     // telport the ship 

      foreach (Enemy e in enemies)   // Teleport everything else which is onscreen 
      { 
       if (!IsOffScreen(e.bodyAABB))  // using old AABB 
       { 
        e.Teleport(tp, 0); 
       } 
      } 
     } 

     foreach(Enemy e in enemies) 
     { 
      e.UpdateAABB();       // calc new AABB for this body 

      if (IsOffScreen(g.bodyAABB))   // camera has not been teleported yet, it's still looking at where the ship was 
      { 
       float x = e.GetPosition().X; 

       // everything which will come onto the screen next frame gets teleported closer to where the camera will be when it catches up with the ship 

       if (e.bodyAABB.UpperBound.X < 0 || e.bodyAABB.LowerBound.X + Landscape.LandscapeWidth() <= cameraPos.X + screenWidth) 
       { 
        e.Teleport(Landscape.LandscapeWidth(), 0); 
       } 
       else if (e.bodyAABB.LowerBound.X > Landscape.LandscapeWidth() || e.bodyAABB.UpperBound.X - Landscape.LandscapeWidth() >= cameraPos.X - screenWidth) 
       { 
        e.Teleport(-Landscape.LandscapeWidth(), 0); 
       } 
      } 
     } 
    }