나는 다음을 구현했습니다. 이는 결코 이상적이지는 않지만 제 목적에 부합합니다. 많은 제약이 있으며 실제 랩핑이 아니지만 충분합니다.
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);
}
}
}
}
여기에 플래시가 있습니까? 사람들이 쉽게 질문을 찾을 수 있도록 적절한 언어 태그를 추가하십시오. –
Box2D는 2D 게임이나 시뮬레이션 개발을위한 OpenGL 백엔드가있는 C++ 라이브러리입니다. –
저는 실제로 C# 포트를 사용하고 있지만 솔루션이 특정 언어 일 것이라고는 생각하지 않습니다. –