//////////////// /// <summary> /// Draws to the main SpriteBatch by way of a callback. Attempts to resolve when to draw based on the SpriteBatch's /// `Begun()` state. /// </summary> /// <param name="draw"></param> /// <param name="isBegun">Indicates that the SpriteBatch was already `Begun()`.</param> /// <param name="forceDraw">Forces drawing even wehn the SpriteBatch is already `Begun()`.</param> /// <returns>`true` if no issues occurred with the drawing.</returns> 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.GetCurrentContext(2) + " - SpriteBatch already begun. Drawing anyway..."); try { draw(Main.spriteBatch); } catch (Exception e) { LogHelpers.WarnOnce(e.ToString()); } } } return(true); }
/// <summary> /// Draws to the main SpriteBatch by way of a callback. Attempts to resolve when to draw based on the SpriteBatch's /// `Begun()` state. If the SpriteBatch needs to be begun anew, the given set of relevant parameters will be applied. /// </summary> /// <param name="draw"></param> /// <param name="sortMode"></param> /// <param name="blendState"></param> /// <param name="samplerState"></param> /// <param name="depthStencilState"></param> /// <param name="rasterizerState"></param> /// <param name="effect"></param> /// <param name="transformMatrix"></param> /// <param name="isBegun">Indicates that the SpriteBatch was already `Begun()`.</param> /// <param name="forceBeginAnew">Forces the SpriteBatch to `Begin()`.</param> /// <param name="forceDraw">Forces drawing even wehn the SpriteBatch is already `Begun()`.</param> /// <returns></returns> 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 && forceBeginAnew) { isBegun = false; Main.spriteBatch.End(); } 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.GetCurrentContext(2) + " - SpriteBatch already begun. Drawing anyway..."); try { draw(Main.spriteBatch); } catch (Exception e) { LogHelpers.WarnOnce(e.ToString()); } } } return(true); }