• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Windows [Solved] Drawing waypoints.

S

Symmetrik

Guest
Alright so currently I've got this waypoint movement system up and working. I'd like to be able to draw the lines from each waypoint in a "connect the dots" fashion. Each waypoint is stored in a respective ds_list for both the x and y coordinates. So how would I be able to draw all the lines at once in a draw event per say?
 
Last edited by a moderator:
L

Lars Karlsson

Guest
The waypoints stored in the list, are they actual objects?
 

DukeSoft

Member
Loop through the list and draw a line from the X and Y of the current one to the X and Y of the next one (if it exists) ?
 

Alexx

Member
You can use draw_line from point to point.
Or use draw_primitive_* / draw_vertex.
If this also a path that an object is following, you could draw the path, or even make a path from these points.

As Lars Karlsson mentioned, how you go about coding this will depend if your list is objects or points. Either of the above would work fine for this.
 
S

Symmetrik

Guest
The waypoints stored in the list, are they actual objects?
Sorry, I meant to say that the x and y coordinates are stored in their own respective ds_list's.

Loop through the list and draw a line from the X and Y of the current one to the X and Y of the next one (if it exists) ?
Would a for loop do the trick for this? What is the best looping method that would make the drawing look seamless?
 
Last edited by a moderator:
L

Lars Karlsson

Guest
Here's one way of doing it.

Code:
[Create Event]
waypoints = ds_list_Create();
Code:
[Draw Event]
draw_self();

if (ds_list_size(waypoints) > 0)
{
    // Draw line from the object to the first point
    draw_line(x, y, waypoints[| 0].x, waypoints[| 0].y);

    // Loop through all points except the last one
    for (var i = 0; i < ds_list_size(waypoints) -1; i++)
    {
        // Draw a line from the current point to the next one.
        draw_line(waypoints[| i].x, waypoints[| i].y, waypoints[| i+1].x, waypoints[| i+1].y);
    }
}

This doesn't look very nice though. So you might want to swap out the draw_line with something that Alexx mentioned
 

Alexx

Member
Here is another approach using primitives:
Assumes your data is in xlist and ylist, change these values accordingly.
I dumbed it down for clarity, you could use accessors as Lars Karlsson did


Code:
///draw points as connected lines
//variables
var i;
var size=ds_list_size(xlist);
//set type
draw_primitive_begin(pr_linestrip);
//loop through points and add to primitive
for (var i = 0; i < size; i += 1)
{
    var xpoint=ds_list_find_value(xlist, i);
    var ypoint=ds_list_find_value(ylist, i);
    draw_vertex(xpoint,ypoint);
}
//last to first point
var xpoint=ds_list_find_value(xlist, 0);
var ypoint=ds_list_find_value(ylist, 0);
draw_vertex(xpoint,ypoint);
//finish primitive
draw_primitive_end();
 
S

Symmetrik

Guest
Here is another approach using primitives:
Assumes your data is in xlist and ylist, change these values accordingly.
I dumbed it down for clarity, you could use accessors as Lars Karlsson did


Code:
///draw points as connected lines
//variables
var i;
var size=ds_list_size(xlist);
//set type
draw_primitive_begin(pr_linestrip);
//loop through points and add to primitive
for (var i = 0; i < size; i += 1)
{
    var xpoint=ds_list_find_value(xlist, i);
    var ypoint=ds_list_find_value(ylist, i);
    draw_vertex(xpoint,ypoint);
}
//last to first point
var xpoint=ds_list_find_value(xlist, 0);
var ypoint=ds_list_find_value(ylist, 0);
draw_vertex(xpoint,ypoint);
//finish primitive
draw_primitive_end();
Thanks so much, works like a charm!
 
Top