OneNightDuel/FNAF_Clone/GUI/TimerUIElement.cs

31 lines
No EOL
777 B
C#

using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace FNAF_Clone.GUI;
public class TimerUIElement : TextUIElement{
private Stopwatch stopwatch = new();
public TimerUIElement(Point corner1, SpriteFont font) : base(corner1, font) {
Text = "00:00.000";
Bounds = (corner1, corner1 + new Point((int)Measure().X, (int)Measure().Y));
}
public override void Update() {
if (stopwatch.IsRunning){
Text = stopwatch.Elapsed.ToString("mm\\:ss\\.fff");
// Text = stopwatch.ElapsedMilliseconds.ToString();
}
}
public void Start() {
stopwatch.Restart();
}
public void Stop() {
stopwatch.Stop();
}
}