Example #1
0
        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;
            }
        }
Example #2
0
 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;
 }
Example #3
0
        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();
            }
        }
Example #4
0
        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);
        }
Example #5
0
 public UpdateTimer(TimeSpan period, UpdateTimer.Type type, TimerEventHandler timeEventHandler = null)
     : this(period.Ticks, type, timeEventHandler)
 {
 }