The "draw_get_surface" Function

Syntax#

draw_get_surface(surf);
ArgumentTypeDescription
surfsurfaceThe surface to retrieve from memory

Description#

Surfaces are "volatile", meaning their data can be erased from memory under certain common conditions, such as resizing or minimizing the game window.

This function will return the surface from cached memory to ensure it always exists before drawing. Unlike normal if (surface_exists(surf)) statements, draw_get_surface will also preserve surface contents, so you never need to regenerate the surface manually. This is especially useful when surfaces are drawn to dynamically and cannot be recreated, such as for blood splatter or tire tracks resulting from unique and unrepeatable player actions.

Though it might seem strange to input and return the same variable, this is necessary because the input surface ID might change if the surface does not exist and must be recreated.

Example#

my_surf = draw_get_surface(my_surf);
draw_surface_ext(my_surf, x, y, 1.5, 1.5, 25, c_red, 0.5);