Esempio n. 1
0
        /// <summary>
        /// Call everytime we want a game redraw. Should be called at the highest frames per second that
        /// the game uses.
        /// </summary>
        public void DrawGame()
        {
            if (selfTiming)
            {
                if (!fpsTimer.TimeElapsed())
                {
                    return;
                }
                fpsTimer.Reset();
                fpsTimer.Start();
            }

            foreach (IDrawable cgd in drawables)
            {
                cgd.Draw(formBuffer.Graphics);
            }
            formBuffer.Render();
        }
Esempio n. 2
0
        /// <summary>
        /// Tells this AnimationManager to draw all current objects on the given
        /// Graphics object
        /// </summary>
        /// <param name="p_g">the Graphics object onwhich to draw</param>
        public void RunNext(Graphics p_g)
        {
            if (selfTiming)
            {
                if (!fps.TimeElapsed())
                {
                    return;
                }
                fps.Reset();
                fps.Start();
            }

            int removeIndex = 0; // we need to remember how many completed objects to delete

            // A list of AnimationObjects that have completed on this run
            Sprite[] aoToRemove = new Sprite[animationObjects.Count];

            foreach (Sprite animationObject in animationObjects)
            {                                          // Run each Sprite in turn
                if (animationObject.RunNext(p_g) == 1) // a return of 1 indicates completion
                {                                      // Remember to remove this object since it is done
                    aoToRemove[removeIndex++] = (Sprite)(animationObject);
                }
            }

            for (int i = 0; i < removeIndex; i++)
            {   // remove all completed Animation objects from list and
                // call the completion event for each (before removal)
                aoToRemove[i].CallCompletionEvent();
                animationObjects.Remove(aoToRemove[i]);
            }
            if (animationObjects.Count == 0)
            {
                running = false;
            }
        }