Ejemplo n.º 1
0
 protected void DrawState(GameTime gameTime, SpartaState state)
 {
     //state.OnBeforeDraw(gameTime, SpriteBatch);
     state.Draw(gameTime, SpriteBatch);
     state.OnPostDraw(gameTime, SpriteBatch);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            SpartaState[] spartaStates = states.Array;
            int           count        = states.Count;

            SpartaState activatedState     = null;
            SpartaState transitionInState  = null;
            SpartaState transitionOutState = null;

            for (int i = 0; i < count; i++)
            {
                if (spartaStates[i].Mode == SpartaState.SpartaStateMode.Activated)
                {
                    activatedState = spartaStates[i];
                    break;
                }
                else if (spartaStates[i].Mode == SpartaState.SpartaStateMode.TransitionIn)
                {
                    transitionInState = spartaStates[i];
                }
                else if (spartaStates[i].Mode == SpartaState.SpartaStateMode.TransitionOff)
                {
                    transitionOutState = spartaStates[i];
                }
            }

            if (activatedState != null)
            {
                activatedState.OnBeforeDraw(gameTime, SpriteBatch);
                GraphicsDevice.Clear(BackgroundColor);
                DrawBackgroundImage();
                activatedState.Draw(gameTime, SpriteBatch);
                activatedState.OnPostDraw(gameTime, SpriteBatch);
            }
            else
            {
                if (transitionOutState != null)
                {
                    transitionOutState.OnBeforeDraw(gameTime, SpriteBatch);
                }
                if (transitionInState != null)
                {
                    transitionInState.OnBeforeDraw(gameTime, SpriteBatch);
                }
                GraphicsDevice.Clear(BackgroundColor);
                DrawBackgroundImage();
                bool stopDrawing = false;
                if (transitionInState != null && transitionOutState != null)
                {
                    if (transitionInState.DrawPriority)
                    {
                        DrawState(gameTime, transitionOutState);
                        DrawState(gameTime, transitionInState);
                        stopDrawing = true;
                    }
                    else if (transitionOutState.DrawPriority)
                    {
                        DrawState(gameTime, transitionInState);
                        DrawState(gameTime, transitionOutState);
                        stopDrawing = true;
                    }
                }
                if (!stopDrawing)
                {
                    if (transitionOutState != null)
                    {
                        DrawState(gameTime, transitionOutState);
                    }
                    if (transitionInState != null)
                    {
                        DrawState(gameTime, transitionInState);
                    }
                }
            }
#if DEBUG
            SpartaDebug.Draw(SpriteBatch);
#endif
        }