Scripting 13 - Visual debugging
Scripting in SFD assumes you have a fair knowledge of C#.
The following code demonstrates how to draw lines, circles and areas for debugging information on the next drawn frame while testing your map in the map editor. This debug information only works while testing your map in the map editor! It also requires you to enable "Show Script Debug Information" in the map debug options meny (F7). Available in v.1.3.0.
The visual debug information is cleared after the next drawn frame so if you want to constantly monitor some information you need to keep drawing it in an update loop.
Code: Select all
public void OnStartup()
{
if (Game.IsEditorTest) {
Events.UpdateCallback.Start(DrawDebugOnUpdate, 0);
}
}
public void DrawDebugOnUpdate(float ms)
{
Game.DrawLine(Vector2.Zero, Vector2.One * 10f, Color.Red);
Game.DrawLine(Vector2.Zero, Vector2.One * -10f, Color.Blue);
Game.DrawCircle(Vector2.Zero, 1f);
Game.DrawCircle(Vector2.Zero, 2f, Color.Yellow);
Game.DrawCircle(Vector2.Zero, 4f, Color.Red);
Game.DrawCircle(Vector2.One * 10f, 4f, Color.Red);
Game.DrawText("ABC", Vector2.Zero, Color.Yellow);
Game.DrawArea(Game.GetObject("AT").GetAABB(), Color.Yellow);
}
ScriptAPI Implementation for ObjectDamageCallback
► Show Spoiler
Code: Select all
In the Game class:
/// <summary>
/// Draws a debugging line to be shown next drawn frame.
/// Note: You must enable "Show Script Debug Information" in the map debug options before this is shown.
/// Note: All debug information will be accumulated until the next drawn frame is rendered, several updates can run between drawn frames.
/// Note: Max 512 lines available in total to be drawn.
/// </summary>
/// <param name="p1">World position A</param>
/// <param name="p2">World position B</param>
/// <param name="c">Color</param>
public abstract void DrawLine(Vector2 p1, Vector2 p2, Color c);
/// <summary>
/// Draws a debugging line to be shown next drawn frame.
/// Note: You must enable "Show Script Debug Information" in the map debug options before this is shown.
/// Note: All debug information will be accumulated until the next drawn frame is rendered, several updates can run between drawn frames.
/// Note: Max 512 lines available in total to be drawn.
/// </summary>
/// </summary>
/// <param name="p1">World position A</param>
/// <param name="p2">World position B</param>
public abstract void DrawLine(Vector2 p1, Vector2 p2);
/// <summary>
/// Draws a debugging circle to be shown next drawn frame.
/// Note: You must enable "Show Script Debug Information" in the map debug options before this is shown.
/// Note: All debug information will be accumulated until the next drawn frame is rendered, several updates can run between drawn frames.
/// Note: Max 512 circles available in total to be drawn.
/// </summary>
/// </summary>
/// <param name="center">World position for the circle's center</param>
/// <param name="radius">Radius</param>
/// <param name="c">Color</param>
public abstract void DrawCircle(Vector2 center, float radius, Color c);
/// <summary>
/// Draws a debugging circle to be shown next drawn frame.
/// Note: You must enable "Show Script Debug Information" in the map debug options before this is shown.
/// Note: All debug information will be accumulated until the next drawn frame is rendered, several updates can run between drawn frames.
/// Note: Max 512 circles available in total to be drawn.
/// </summary>
/// <param name="center">World position for the circle's center</param>
/// <param name="radius">Radius</param>
public abstract void DrawCircle(Vector2 center, float radius);
/// <summary>
/// Draws a debugging area to be shown next drawn frame.
/// Note: You must enable "Show Script Debug Information" in the map debug options before this is shown.
/// Note: All debug information will be accumulated until the next drawn frame is rendered, several updates can run between drawn frames.
/// Note: Max 256 areas available in total to be drawn.
/// </summary>
/// <param name="area">Area</param>
/// <param name="c">Color</param>
public abstract void DrawArea(Area area, Color c);
/// <summary>
/// Draws a debugging area to be shown next drawn frame.
/// Note: You must enable "Show Script Debug Information" in the map debug options before this is shown.
/// Note: All debug information will be accumulated until the next drawn frame is rendered, several updates can run between drawn frames.
/// Note: Max 256 areas available in total to be drawn.
/// </summary>
/// <param name="area">Area</param>
public abstract void DrawArea(Area area);
/// <summary>
/// Draws a debugging text to be shown next drawn frame.
/// Note: You must enable "Show Script Debug Information" in the map debug options before this is shown.
/// Note: All debug information will be accumulated until the next drawn frame is rendered, several updates can run between drawn frames.
/// Note: Max 128 texts available in total to be drawn.
/// </summary>
/// <param name="text">Text to be drawn. The shorter the better.</param>
/// <param name="position">World position</param>
/// <param name="c">Color</param>
public abstract void DrawText(string text, Vector2 position, Color c);
/// <summary>
/// Draws a debugging text to be shown next drawn frame.
/// Note: You must enable "Show Script Debug Information" in the map debug options before this is shown.
/// Note: All debug information will be accumulated until the next drawn frame is rendered, several updates can run between drawn frames.
/// Note: Max 128 texts available in total to be drawn.
/// </summary>
/// <param name="text">Text to be drawn. The shorter the better.</param>
/// <param name="position">World position</param>
public abstract void DrawText(string text, Vector2 position);