Is there a faster way to draw a thick line, when using draw_path();?

O

Olivebates

Guest
Hi!

I want to draw a thick line as a path.
Right now I'm using the following code.
Is there any way to optimize this?
I think it's making my game lag to draw this many paths, and it also looks bad.

Code:
// Draw line
draw_set_color(c_red);
draw_path(ip, ix, iy, false);

draw_path(ip, ix+.25, iy, false);
draw_path(ip, ix-.25, iy, false);
draw_path(ip, ix, iy+.25, false);
draw_path(ip, ix, iy-.25, false);

draw_path(ip, ix+.5, iy, false);
draw_path(ip, ix-.5, iy, false);
draw_path(ip, ix, iy+.5, false);
draw_path(ip, ix, iy-.5, false);

draw_path(ip, ix+.75, iy, false);
draw_path(ip, ix-.75, iy, false);
draw_path(ip, ix, iy+.75, false);
draw_path(ip, ix, iy-.75, false);

draw_path(ip, ix+1, iy, false);
draw_path(ip, ix-1, iy, false);
draw_path(ip, ix, iy+1, false);
draw_path(ip, ix, iy-1, false);

//Draw outline
draw_set_color(c_black);

draw_path(ip, ix+1.25, iy, false);
draw_path(ip, ix-1.25, iy, false);
draw_path(ip, ix, iy+1.25, false);
draw_path(ip, ix, iy-1.25, false);

draw_path(ip, ix+1.5, iy, false);
draw_path(ip, ix-1.5, iy, false);
draw_path(ip, ix, iy+1.5, false);
draw_path(ip, ix, iy-1.5, false);
Thanks! :D
 
A

anomalous

Guest
A few ways.
In general, you should look at the path functions for getting the path points.
Loop through each point, and draw a line between each path point. This is the core code.

You can then draw the line using draw_line_width in one pass, to draw a thicker line.
Also, draw_line_width_colour can get you some interesting gradient effects.

For a fancier look and additional optimization, you can create a sprite that can be stretched without changing how it looks.
Then draw this stretched between those two points, its likely a bit faster than the draw primitive line.

If the paths do not change, for each path you can create a surface and draw the sprites/lines to the surface, then draw the surface to the screen. This has tradeoffs/overhead, but if its a lot of paths, and they don't update every step, this could save even more.
 

Kubawsky

Member
Anomalous, what if the path is not a straight line and also changes shape (possibly at every frame).
Any ideas?
 

Kubawsky

Member
For a fancier look and additional optimization, you can create a sprite that can be stretched without changing how it looks.
Can you explain what you mean by this?
Such a solution would work for me - other solutions are too heavy as I'm scaling and shifting the path every step and then drawing it multiple times, every step :)
I made a test with a sprite that is shaped like my path, it is a little CPU-heavy but doesn't lag the game. But obviously stretching it disproportionately looks bad - that's why my interest in your comment :)

If draw_path had a width parameter, that would solve my problem...
 
Top