In the normal draw events, GameMaker Studio 2 doesn't actually draw directly to the screen, but rather draws to a surface called the application surface. This surface is basically a blank "canvas" that can then later be manipulated before being drawn to the screen when needed, and in most cases GameMaker Studio 2 handles this for you (although you can also manipulate it yourself in code for shaders, scaling and many other things - further details are given below).

However, apart from this application surface, you can also create your own surfaces and use them to create stunning or subtle special effects in your game. For example, you can use surfaces to "catch" instances, which can then be destroyed, and in this way you can create a decal effect where the sprite for the instance is displayed on the surface as if it still existed, permitting graphical effects like debris, blood, etc... without any real processing overhead. Another thing you can do with surfaces is use them as textures to be manipulated, or to create sprites "on the fly", or to create complex overlays. in fact, the uses for surfaces are endless!

Normal surfaces are quite easy to use, but there are a few basic rules to be followed when you use them:

The basic use of a surface would be as follows - You first create a surface and assign its index to a variable. You would then set the drawing target to the surface rather than the display and draw the things you wish as well as perform any other manipulations. Once you are done you reset the drawing target so that all further drawing happens on the screen again. One thing to note is that should you require drawing the whole display to a surface (including tiles, backgrounds etc...) you can simply access the application surface itself (see below for further details) or you could assign a surface to a view port using the variable view_surface_id[0..7] as with this all that is visible in that view port will be drawn to the corresponding surface.

The following functions exist to deal with surfaces (these functions are specific for creating and manipulating surfaces, but to actually draw them to the screen you should be using the specific draw functions that can be found in the section on Surface Drawing, below):

As mentioned above, all normal drawing in your game is done on the application surface, and this surface can be changed and manipulated just like a normal surface. However, it is not a normal surface and advanced users will find that it enables complete control over how and when things are drawn in GameMaker Studio 2. For more details, as well as specific functions for this feature, please see the following section:

  1. The Application Surface

The following variable exists for referencing the application surface:

And you also have a few special functions that are designed only for use with the application surface:

Surfaces are an incredibly powerful graphic tool that GameMaker Studio 2 provides you for creating special effects and a whole host of other things. They are relatively simple to use as they are basically a canvas that you draw to instead of the display screen, and this canvas can then be manipulated and changed before being drawn with the functions in this section.

NOTE: When working with surfaces there is the possibility that they can cease to exist at any time due to them being stored in texture memory. You should ALWAYS check that a surface exists using surface_exists before referencing them directly.

The following functions exist for drawing surfaces:

  1. draw_surface
  2. draw_surface_ext
  3. draw_surface_part
  4. draw_surface_part_ext
  5. draw_surface_stretched
  6. draw_surface_stretched_ext
  7. draw_surface_tiled
  8. draw_surface_tiled_ext
  9. draw_surface_general