Class Timer
- Namespace
- BSGameLib.Game.Components
- Assembly
- BSGameLib.Game.dll
Calls ElapsedAction each time Interval has passed while the timer is running.
public class Timer : Component, IUpdateable, IIdentifiable<Guid>, IEquatable<IUpdateable>
- Inheritance
-
Timer
- Implements
- Inherited Members
Remarks
The timer checks the clock in Update(IGameTime), so it can fire no more often than the game updates it. If several intervals pass between updates it fires once, not once per interval.
Constructors
Timer(TimeSpan, Action)
Creates a stopped timer that calls elapsedAction every interval once started with Start().
public Timer(TimeSpan interval, Action elapsedAction)
Parameters
Properties
ElapsedAction
Called when the interval has passed. Null is allowed; nothing is called.
public Action ElapsedAction { get; set; }
Property Value
Interval
The time between firings. A change applies from the next Update(IGameTime).
public TimeSpan Interval { get; set; }
Property Value
IsRunning
public bool IsRunning { get; }
Property Value
Methods
Start()
Starts the timer, counting from now. Does nothing if it is already running.
public void Start()
Stop()
Stops the timer. A later Start() counts from the time of that call.
public void Stop()
Update(IGameTime)
Calls ElapsedAction if Interval has passed since the timer was started or last fired. It fires at most once per call.
public override void Update(IGameTime gameTime)
Parameters
gameTimeIGameTime