-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackgroundLayer.cs
More file actions
34 lines (30 loc) · 1.05 KB
/
BackgroundLayer.cs
File metadata and controls
34 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using System;
namespace ProgGame
{
public class BackgroundLayer
{
public Texture2D texture;
public float scrollRate;
public BackgroundLayer(ContentManager content, string path, float scrollRate)
{
texture = content.Load<Texture2D>(path);
this.scrollRate = scrollRate;
}
public void Draw(SpriteBatch spriteBatch, Vector2 cameraPosition)
{
int segmentWidth = texture.Width;
float x = cameraPosition.X * scrollRate;
int leftSegment = (int)Math.Floor(x / segmentWidth);
x = (x / segmentWidth - leftSegment) * -segmentWidth;
var totalX = x;
for (int i = 0; i < (spriteBatch.GraphicsDevice.Viewport.Width % segmentWidth) + 1; ++i)
{
totalX += segmentWidth;
spriteBatch.Draw(texture, new Vector2(totalX, cameraPosition.Y - 208), Color.White);
}
}
}
}