• 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!

GameMaker Useful functions for the Draw Event

Suzaku

Member
Im starting to learn how to use the draw event to draw everything in the game and I would like to know some of the most common and useful functions that are helpful to work with the draw event, not only "draw_" functions, I want functions like something to get the borders of the drawn sprites to place them correctly, or to make them be animated, and everything else that you think it is useful. Thank you for your time.
 

PlayerOne

Member
Look at the manual to understand each function and experiment. Best way you can learn.

One thing I can say is this: Using drawing functions in GM requires you to understand "draw order". It operates the same as object depth as far as I can describe it.

For example take this:

Code:
draw_set_color(c_black)
draw_rectangle(0,0,room_width,room_height,false)

draw_set_color(c_white)
draw_text(50,50,"Hello World!")
If you wrote the code like this the text will draw on top of the rectangle.

Code:
draw_set_color(c_white)
draw_text(50,50,"Hello World!")

draw_set_color(c_black)
draw_rectangle(0,0,room_width,room_height,false)
If you wrote the code like this the text will draw on under the rectangle. Not many know this and it's good to remember what order each draw function is being executed.
 

FrostyCat

Redemption Seeker
Those "useful functions" were right under your nose this whole time. These are what experienced users use to place drawn graphics properly:
  • Addition and subtraction for offsetting distances
  • Multiplication and division for scaling distances
  • Trigonometric functions for handling certain kinds of geometry that involves both angles and distances
  • lengthdir_x() and lengthdir_y() for converting polar to rectangular coordinates
  • Sprite property functions like sprite_get_width() and sprite_get_height()
  • Font-sensitive string functions like string_width() and string_height()
Chances are you'd know what all of those functions are. If you still can't get stuff drawn where you want them to be, it's because your foundation in basic plane geometry is inadequate, not because there's some magical solution we didn't tell you about.

Also, learn how to draw and read blueprints. Formulas used in drafting for positioning, proportioning and distributing elements are as applicable on paper as on screen, and most of the math in an average 2D game's graphics code reduces to some variation of these.
 
Top