Debug-Draw - Lines, boxes, circles, etc

I made a little module of convenience functions to help draw lines, shapes, and text for visual debugging. The render “draw_line” and “draw_text” messages are really long and cumbersome to type, so this wraps them up and makes things simple. It’s not an exhaustive shape-drawing library, just enough to draw a few different kinds of indicators and things.

You can use it as a library dependency with the following link, or just grab the lua file and drop it in your project wherever suits you.

https://github.com/rgrams/debug-draw/archive/master.zip

See the Readme on github for documentation (though it’s all pretty straightforward).

27 Likes

Add it to our asset portal, it’s great and convenient :smiley:

2 Likes

Yeah I know. :stuck_out_tongue: Since the dashboard’s going to be removed and the asset portal shuffled around in a few weeks I figured I might as well wait.

3 Likes

Hello!

I just discovered your library, it looks soooo convenient!

I just followed the instructions here (Working with library projects in Defold), but… can’t make it work :frowning:

The library seems to be properly installed:
debugdraw001

But this simple line…
debugdraw.circle(100,100,100) (in the “update” function)

… generates an error message:
debugdraw002

Did I miss something?

Rag’

1 Like

How do you “require” the Lua module?

1 Like

require "debug-draw.debug-draw"

1st line of the same script

:thinking:

1 Like

Then you’ll get the variable “debug-draw”, and not the “debugdraw” as you wrote.

Try this instead:

local debugdraw = require("debug-draw.debug-draw")
4 Likes

Oh ok… As you expected, it works :slight_smile:

Thank you very much Ross for this super useful library, and Mathias for the help!

2 Likes

Thanks Mathias for helping out. I’ve added a line about this to the readme.

2 Likes

debug-draw.zip (12.6 KB)

Updated version with more features and a nice animated demo! @ross.grams If you’re interested in updating the main repo version still please do.

13 Likes

First of all, thanks for the demo! Really nice!

I don’t know if this is a known issue or it is an issue only on my mac. But text is not aligned with the other graphic elements. It seems like text is not behaving well with window size changing. Here is a screenshot:

Demo is meant for demonstration so not really an issue. You can position debug draw text however you want but for a real game you want to use labels / gui text anyway.

Yes, of course, this is only for debug.

I like this demo so much and, in my opinion, it is a pity that the labels haven’t the correct positions. Just this.

Thanks again!

1 Like

The fix is to apply the display scale:

function M.text(text, x, y, color)
	local scale = window.get_display_scale()
	color = color or M.default_color
	if M.COLORS[color] then  color = M.COLORS[color]  end
	V1.x, V1.y = x * scale, y * scale
	TEXTMSGDATA.text, TEXTMSGDATA.position, TEXTMSGDATA.color = text, V1, color
	msg.post("@render:", "draw_debug_text", TEXTMSGDATA)
end

The display scale should obviously be cached and not called every time.

3 Likes