Tôi đã thực hiện những điều sau đây, điều này không có ý nghĩa lý tưởng nhưng phù hợp với mục đích của tôi. Có rất nhiều hạn chế liên quan và nó không phải là một thế giới gói thực sự nhưng nó đủ tốt.
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);
}
}
}
}
Nguồn
2009-05-27 08:27:37
Chúng ta có trong Flash ở đây không? Vui lòng thêm thẻ ngôn ngữ thích hợp để mọi người có thể tìm thấy câu hỏi dễ dàng hơn. –
Box2D là một thư viện C++ với phụ trợ OpenGL để phát triển trò chơi hoặc mô phỏng 2D. –
Tôi thực sự đang sử dụng cổng C# nhưng tôi không nghĩ giải pháp sẽ là ngôn ngữ cụ thể –