Designing Games with GameMaker
Drawing shapes
There is a whole collection of functions available to draw different shapes. Also there are functions to draw text (see next section). You can only use these in the drawing event of an object; these functions in general don't make any sense anywhere else in code. Realize that collisions between instances are determined by their sprites (or masks) and not by what you actually draw. The following drawing functions exist that can be used to draw basic shapes.
draw_clear(col) Clears the entire room in the given color (no alpha blending).
draw_clear_alpha(col,alpha) Clears the entire room in the given color and alpha value (in particular useful for surfaces).
draw_point(x,y) Draws a point at (x,y) in the current color.
draw_line(x1,y1,x2,y2) Draws a line from (x1,y1) to (x2,y2).
draw_line_width(x1,y1,x2,y2,w) Draws a line from (x1,y1) to (x2,y2) with width w.
draw_rectangle(x1,y1,x2,y2,outline) Draws a rectangle. outline indicates whether only the outline must be drawn (true) or it should be filled (false).
draw_roundrect(x1,y1,x2,y2,outline) Draws a rounded rectangle. outline indicates whether only the outline must be drawn (true) or it should be filled (false).
draw_triangle(x1,y1,x2,y2,x3,y3,outline) Draws a triangle. outline indicates whether only the outline must be drawn (true) or it should be filled (false).
draw_circle(x,y,r,outline) Draws a circle at (x,y) with radius r. outline indicates whether only the outline must be drawn (true) or it should be filled (false).
draw_ellipse(x1,y1,x2,y2,outline) Draws an ellipse. outline indicates whether only the outline must be drawn (true) or it should be filled (false).
draw_set_circle_precision(precision) Sets the precision with which circles are drawn, that is, the number of segments they consist of. The precision must lie between 4 and 64 and must be dividable by 4. This is also used for drawing ellipses and rounded rectangles.
draw_arrow(x1,y1,x2,y2,size) Draws an arrow from (x1,y1) to (x2,y2). size indicates the size of the arrow in pixels.
draw_button(x1,y1,x2,y2,up) Draws a button, up indicates whether up (1) or down (0).
draw_path(path,x,y,absolute) With this function you can draw the indicated path in the room with its start at position (x,y). If absolute is true the path is drawn at the position where it was defined and the values of x and y are ignored.
draw_healthbar(x1,y1,x2,y2,amount,backcol,mincol,maxcol,direction,showback,showborder) With this function you can draw a healthbar (or any other bar that indicates some value, like e.g. the damage). The arguments x1, y1, x2 and y2 indicate the total area for the bar. amount indicates the percentage of the bar that must be filled (must lie between 0 and 100). backcol is the color of the background for the bar. mincol and maxcol indicate the color when the amount is 0 and 100 respectively. For an amount in between the color is interpolated. So you can easily make a bar that goes e.g. from green to red. The direction is the direction in which the bar is drawn. 0 indicates that the bar is anchored at the left, 1 at the right, 2 at the top and 3 at the bottom. Finally showback indicates whether a background box must be shown and showborder indicated whether the box and bar should have a black border line.
Most of the above functions use the color and alpha setting that can be changed with following functions.
draw_set_color(col) Sets the drawing color to be used from now on for drawing primitives.
draw_set_alpha(alpha) Sets the alpha transparency value to be used from now on for drawing primitives. Should lie in the range 0-1. 0 is fully transparent, 1 is fully opaque.
draw_get_color() Returns the drawing color used for drawing primitives.
draw_get_alpha() Returns the alpha value used for drawing primitives.
A whole range of predefined colors is available:
c_aqua
c_black
c_blue
c_dkgray
c_fuchsia
c_gray
c_green
c_lime
c_ltgray
c_maroon
c_navy
c_olive
c_orange
c_purple
c_red
c_silver
c_teal
c_white
c_yellow
The following functions can help you to create the colors you want.
make_color_rgb(red,green,blue) Returns a color with the indicated red, green, and blue components, where red, green and blue must be values between 0 and 255.
make_color_hsv(hue,saturation,value) Returns a color with the indicated hue, saturation and value components (each between 0 and 255).
color_get_red(col) Returns the red component of the color.
color_get_green(col) Returns the green component of the color.
color_get_blue(col) Returns the blue component of the color.
color_get_hue(col) Returns the hue component of the color.
color_get_saturation(col) Returns the saturation component of the color.
color_get_value(col) Returns the value component of the color.
merge_color(col1,col2,amount) Returns a merged color of col1 and col2. The merging is determined by amount. A value of 0 corresponds to col1, a value of 1 to col2, and values in between to merged values.
The following miscellaneous functions exist.
draw_getpixel(x,y) Returns the color of the pixel corresponding to position (x,y) in the room. This is not very fast, so use with care.
screen_save(fname) Saves a png image of the screen in the given filename. Useful for making screenshots.
screen_save_part(fname,x,y,w,h) Saves part of the screen in the given png filename.
Alternative versions
You can also read this manual on one single long page (± 1.5 mb)
Also available in:
Download helpfile
Also available in:
Download helpfile