Table of Contents

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

interval TimeSpan
elapsedAction Action

Properties

ElapsedAction

Called when the interval has passed. Null is allowed; nothing is called.

public Action ElapsedAction { get; set; }

Property Value

Action

Interval

The time between firings. A change applies from the next Update(IGameTime).

public TimeSpan Interval { get; set; }

Property Value

TimeSpan

IsRunning

Whether the timer is running, between Start() and Stop().

public bool IsRunning { get; }

Property Value

bool

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

gameTime IGameTime