質問

私はBOX2Dと無限のラップの世界を作成する必要があります(Xは、すべてのオブジェクトの座標0

カメラは時間(約5%の幅、100%の高さ - ワールドワイド1000で約30高い)で世界の小さな部分のみを見ることができます。

乾杯ます。

役に立ちましたか?

解決

私は決して理想的ではなく、私の目的に適合している、次のように実装しました。そこ関わる多くの制限があり、それが真のラッピング世界ではないのですが、それは十分だ。

    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);
                }
            }
        }
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top