1
\$\begingroup\$

Let's say I want to start from the center pixel of a screen of indeterminate size, and I want to be able to draw an arrow from this center pixel to any other pixel.

The only way I know how to do that is to assign entirely new sprites for each and every possible direction and magnitude of the vector...which might work (even if it's tedious) for around 10 or even 20 possible combinations, but much more and it would really chug a system with the switch statement alone to find which sprite to use.

So, the obvious, much better, way of doing this is just to dynamically draw from one point to another...I don't know how to though.

\$\endgroup\$
  • \$\begingroup\$ You mean, you want to draw a line with a pointer? \$\endgroup\$ – DH. Jul 24 '16 at 0:36
  • \$\begingroup\$ Yeah. It's already been answered. \$\endgroup\$ – SangoProductions Jul 25 '16 at 1:32
1
\$\begingroup\$

You can draw whatever you want on the screen by using the draw_* functions related to primitive shapes instead of sprites.

As example, we can dinamically draw the velocity vector of any object by considering the built-in variables x, y, hspeed and vspeed, or alternatively the variables speed (which is the magnitude of the combination of hspeed and vspeed) and direction. In the first case, we can draw such vector as follows:

draw_arrow(x,y,x+hspeed,y+vspeed,5);

You can multiply hspeed and vspeed for a given constant if you want arrows to be drawn longer, depending on speed values:

var rt = 2.5;
draw_arrow(x,y,x+rt*hspeed,y+rt*vspeed,5);

If you are working with a magnitude (like speed) and an angle (like direction), or similars, you need to add just few more lines:

// MAG can be any magnitude
// DIR can be any 0-360 angle
var vec_x = lengthdir_x(mag,dir);
var vec_y = lengthdir_y(mag,dir);
draw_arrow(x,y,x+vec_x,y+vec_y,5);

Matter is, you can draw arrows, lines, or even circles (assuming your vector as the circumference radius), etcetera. Also, you can change colour and line style to best fit your game appearance.

\$\endgroup\$
  • \$\begingroup\$ Thanks significantly. I'll look in to the documentation for the draw_* (and specifically draw_arrow functions. \$\endgroup\$ – SangoProductions Jul 25 '16 at 1:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.