This section deals with the functions related to creating and manipulating surfaces.

In the normal draw events, GameMaker: Studio 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 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 using the variable view_surface_id[0..7]as with this all that is visible in that view will be drawn to the corresponding surface.

The following functions exist to deal with surfaces:

  1. surface_exists
  2. surface_create
  3. surface_create_ext
  4. surface_resize
  5. surface_set_target
  6. surface_set_target_ext
  7. surface_reset_target
  8. surface_copy
  9. surface_copy_part
  10. surface_get_height
  11. surface_get_width
  12. surface_get_texture
  13. surface_getpixel
  14. surface_getpixel_ext
  15. surface_free
  16. surface_save
  17. surface_save_part

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 Drawing Surfaces.

The Application Surface

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. For more details, as well as specific functions for this feature, please see the following section:

  1. The Application Surface

Back: Reference
© Copyright YoYo Games Ltd. 2018 All Rights Reserved