Пример #1
0
        /// <summary>Updates the position and orientation of all sprites on each timer tick.</summary>
        /// <param name="sender">The timer.</param>
        /// <param name="e">Event args.</param>
        private void UpdateSpritesOnTimerTick(object sender, EventArgs e)
        {
            if (_timer != null)
            {
                if (_sprites != null)
                {
                    // Update each sprite
                    for (int i = _sprites.Count - 1; i >= 0; --i)
                    {
                        // Update the sprite
                        ImageSprite s = _sprites[i];
                        s.Update();

                        // If it's left the visible range, remove it from the list so we don't
                        // need to deal with it any more
                        Rectangle bounds = ClientRectangle;
                        if (s.Location.X > bounds.Right + s.Image.Width || s.Location.X < -s.Image.Width ||
                            s.Location.Y > bounds.Bottom + s.Image.Width || s.Location.Y < -s.Image.Width)
                        {
                            _sprites.RemoveAt(i);
                            s.Dispose();
                        }
                    }

                    // If there are no sprites left, stop the timer; we're done.
                    if (_sprites.Count == 0)
                    {
                        _timer.Stop();                                          // stop but don't delete, as _timer is used as a marker
                    }
                    // Refresh the window
                    Invalidate();
                }
            }
        }