示例#1
0
        ////////////////

        public static bool DrawBatch(Action <SpriteBatch> draw, out bool isBegun, bool forceDraw = true)
        {
            if (!XnaHelpers.IsMainSpriteBatchBegun(out isBegun))
            {
                return(false);                // take no chances
            }

            if (!isBegun)
            {
                Main.spriteBatch.Begin();

                try {
                    draw(Main.spriteBatch);
                } catch (Exception e) {
                    LogHelpers.WarnOnce(e.ToString());
                }

                Main.spriteBatch.End();
            }
            else
            {
                if (forceDraw)
                {
                    LogHelpers.WarnOnce(DebugHelpers.DebugHelpers.GetCurrentContext(2) + " - SpriteBatch already begun. Drawing anyway...");
                    try {
                        draw(Main.spriteBatch);
                    } catch (Exception e) {
                        LogHelpers.WarnOnce(e.ToString());
                    }
                }
            }

            return(true);
        }
示例#2
0
        public static bool DrawBatch(Action <SpriteBatch> draw,
                                     SpriteSortMode sortMode,
                                     BlendState blendState,
                                     SamplerState samplerState,
                                     DepthStencilState depthStencilState,
                                     RasterizerState rasterizerState,
                                     Effect effect,
                                     Matrix transformMatrix,
                                     out bool isBegun,
                                     bool forceBeginAnew = false,
                                     bool forceDraw      = true)
        {
            if (!XnaHelpers.IsMainSpriteBatchBegun(out isBegun))
            {
                return(false);                // take no chances
            }

            if (!isBegun)
            {
                Main.spriteBatch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix);

                try {
                    draw(Main.spriteBatch);
                } catch (Exception e) {
                    LogHelpers.WarnOnce(e.ToString());
                }

                Main.spriteBatch.End();
            }
            else
            {
                if (forceDraw)
                {
                    LogHelpers.WarnOnce(DebugHelpers.DebugHelpers.GetCurrentContext(2) + " - SpriteBatch already begun. Drawing anyway...");
                    try {
                        draw(Main.spriteBatch);
                    } catch (Exception e) {
                        LogHelpers.WarnOnce(e.ToString());
                    }
                }
            }

            return(true);
        }