Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

Scripting 13 - Visual debugging

A smaller forum with a few tutorials how to get started with the ScriptAPI.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

Scripting 13 - Visual debugging

Post by Gurt » Sun Jul 28, 2019 5:06 pm

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
Last edited by Gurt on Mon Jul 29, 2019 1:37 pm, edited 1 time in total.
Reason: Updated with DrawText()
5 x
Gurt

Post Reply