1

我制作了一个无限滚动的背景,当我提高速度时,两个背景之间的差距变得更大。有什么建议么?我想消除差距,但我不知道如何......差距在我用作背景的两张图片之间。

public class Game1 : Microsoft.Xna.Framework.Game
{
    Texture2D scrollBak1;
    Texture2D scrollBak2;

    Vector2 scroll1Pos;
    Vector2 scroll2Pos;`
}

    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";

        graphics.PreferredBackBufferHeight = 700;
        graphics.PreferredBackBufferWidth = 1050;
    }

    protected override void LoadContent()
    {
        scrollBak1 = Content.Load<Texture2D>("övrigt\\mark");
        scrollBak2 = Content.Load<Texture2D>("övrigt\\mark");

        scroll2Pos = new Vector2(scrollBak1.Width,      graphics.GraphicsDevice.Viewport.Height - scrollBak1.Height);

        scroll1Pos = new Vector2(0, graphics.GraphicsDevice.Viewport.Height - scrollBak1.Height);

    }

    protected override void UnloadContent()
    {
    }

    protected override void Update(GameTime gameTime)
    {

            if (scroll1Pos.X <= -scrollBak1.Width)
            {
                scroll1Pos = new Vector2(scrollBak1.Width - 20, graphics.GraphicsDevice.Viewport.Height - scrollBak1.Height);
                scroll1Pos.Y += 200;
            }

            if (scroll2Pos.X <= -scrollBak2.Width)
            {
                scroll2Pos = new Vector2(scrollBak2.Width - 20, graphics.GraphicsDevice.Viewport.Height - scrollBak2.Height);
                scroll2Pos.Y += 200;
            }
            // speed
            scroll1Pos.X -= 40f;
            scroll2Pos.X -= 40f;

            }

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.White);

        spriteBatch.Begin();

            spriteBatch.Draw(scrollBak2, scroll2Pos, null, Color.White, 0, new Vector2(scroll2Pos.X, scroll2Pos.Y - 500), 0.5f, SpriteEffects.None, 0f);

            spriteBatch.Draw(scrollBak1, scroll1Pos, null, Color.White, 0, new Vector2(scroll1Pos.X, scroll1Pos.Y - 500), 0.5f, SpriteEffects.None, 0f);

        }

        spriteBatch.End();

        base.Draw(gameTime);
    }
}

}

4

0 回答 0