I’m trying to create a scrolling background it works fine on 720p but when scaled to 1080p I get a gap between the images
code:
public class Main_menu
{
private Texture2D _background1;
private Texture2D _background2;
private Vector2 _background1Pos;
private Vector2 _background2Pos;
private float _speed;
private Vector2 _scale;
private Vector2 _HD;
private Vector2 _FULLHD;
public Main_menu()
{
_background1 ??= Globals.Content.Load<Texture2D>("backgrounds\\backgroundEmpty");
_background2 ??= Globals.Content.Load<Texture2D>("backgrounds\\backgroundEmpty");
_HD = new(2.25f, 1.5f);
_FULLHD = new(3f, 2f);
if (Globals.windowheight == 720)
{
_scale = _HD;
}
else if (Globals.windowheight == 1080)
{
_scale = _FULLHD;
}
_speed = -100f;
_background1Pos = new Vector2(0, 0);
_background2Pos = new Vector2(_background1.Width * _scale.X, 0);
Console.WriteLine("{0}, {1} , {2}", _HD, _FULLHD, _scale);
Console.WriteLine("{0}, {1}", _background1.Width * _scale.X, _background1.Height * _scale.Y);
}
public void Update(GameTime gt)
{ //scroling background
_background1Pos.X += _speed * (float)gt.ElapsedGameTime.TotalSeconds;
_background2Pos.X += _speed * (float)gt.ElapsedGameTime.TotalSeconds;
if (_background1Pos.X <= -_background1.Width * _scale.X)
{
_background1Pos.X = Globals.windowwidth;
}
if (_background2Pos.X <= -_background2.Width * _scale.X)
{
_background2Pos.X = Globals.windowwidth;
}
//debug info
}
public void Draw()
{
Globals.SpriteBatch.Draw(_background1, _background1Pos, null, Color.White, 0, Vector2.Zero, _scale, SpriteEffects.None, 1);
Globals.SpriteBatch.Draw(_background2, _background2Pos, null, Color.White, 0, Vector2.Zero, _scale, SpriteEffects.None, 1);
}
}