Cookie – Surfaces in GameMaker: Studio

banner_image

Getting started with drawing to a surface in GameMaker can be scary, especially when you see all the warnings and mystical properties that are associated with them.

The good news is that in reality, there isn’t really that much to them. In the latest release of GameMaker 1.3 the main draw area IS a surface. So you’re working with them already, you just don’t know it.

The main thing you have to remember about surfaces is they aren’t guaranteed to be there, just like biscuits in a biscuit jar, so you have to check they exist before drawing (or eating).

So to get started with surfaces you have to create one, if it doesn’t already exist that is!

 if (!surface_exists(surf))
     surf = surface_create(width, height);

Then you set the target, all drawing after this will be done to the surface.

surface_set_target(surf);
// Here you just draw as normal
// i.e draw_sprite(sprite, subimg, x, y);

Then once you’re done set it back to the application surface. (The standard draw area)

surface_reset_target();‏

Finally you draw the surface to the screen.

draw_surface(surf, x, y);

You can download a example of this from GitHub, just navigate to the page a click “Download Zip”.

So really drawing to a surface isn’t difficult, it just takes a little getting used to. Still have a question? Leave a comment or go ask the very helpful folks at the GameMaker Community.

Leave a Reply

Your email address will not be published. Required fields are marked *