forked from AerysBat/XNALara
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHUD.cs
50 lines (41 loc) · 1.49 KB
/
HUD.cs
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace XNALara
{
public class HUD
{
private const double MessageDisplayInterval = 2000.0; // [ms]
private SpriteBatch spriteBatch;
private SpriteFont font;
private double currentTime;
private string message;
private double messageDisplayedSince;
public HUD(Game game) {
spriteBatch = new SpriteBatch(game.GraphicsDevice);
font = game.Content.Load<SpriteFont>("HUDFont");
}
public string Message {
set {
message = value;
messageDisplayedSince = message != null ? currentTime : -1;
}
}
public void Update(GameTime gameTime) {
currentTime = gameTime.TotalGameTime.TotalMilliseconds;
if (messageDisplayedSince >= 0 &&
currentTime - messageDisplayedSince > MessageDisplayInterval) {
Message = null;
}
}
public void Render() {
if (message != null) {
spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
int x = 10;
int y = 10;
spriteBatch.DrawString(font, message, new Vector2(x + 1, y + 1), Color.Black);
spriteBatch.DrawString(font, message, new Vector2(x, y), Color.Yellow);
spriteBatch.End();
}
}
}
}