1

無限にスクロールする背景を作成しました。速度を上げると、2つの背景の間のギャップが大きくなります。助言がありますか?隙間をなくしたいのですが、どうしたらいいのかわかりません…背景に使っている2枚の写真の間に隙間があります。

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