public UpdateTimer(long ticks, UpdateTimer.Type type, TimerEventHandler timeEventHandler = null) { Debug.Assert(ticks >= 0); _ticksElapsed = 0; _ticksUntilFire = ticks; _ticksInPeriod = ticks; _type = type; _isRunning = true; if (timeEventHandler != null) { TimerFired += timeEventHandler; } }
public void Play(bool randomStartFrame = false) { _index = (randomStartFrame ? _Random.Next(_keyFrames.Count) : 0); _timer = new UpdateTimer(_keyFrames[_index].Duration, UpdateTimer.Type.Once, TimerFired); _ticksToNextFrame = _keyFrames[_index].Duration.Ticks; State = AnimationState.Playing; }
private void PlayToNextFrame(long ticksElapsed) { Debug.Assert(ticksElapsed >= 0); while (ticksElapsed >= _ticksToNextFrame && _index < _keyFrames.Count) { ticksElapsed -= _ticksToNextFrame; if (++_index < _keyFrames.Count) { _ticksToNextFrame = _keyFrames[_index].Duration.Ticks; } } if (_index < _keyFrames.Count) { _ticksToNextFrame -= ticksElapsed; _timer = new UpdateTimer(_ticksToNextFrame, UpdateTimer.Type.Once, TimerFired); } else { Stop(); } }
private void LoopToNextFrame(long ticksElapsed) { Debug.Assert(ticksElapsed >= 0); while (ticksElapsed >= _ticksToNextFrame) { ticksElapsed -= _ticksToNextFrame; _index = (_index + 1) % _keyFrames.Count; _ticksToNextFrame = _keyFrames[_index].Duration.Ticks; } _ticksToNextFrame -= ticksElapsed; _timer = new UpdateTimer(_ticksToNextFrame, UpdateTimer.Type.Once, TimerFired); }
public UpdateTimer(TimeSpan period, UpdateTimer.Type type, TimerEventHandler timeEventHandler = null) : this(period.Ticks, type, timeEventHandler) { }