Login | Register

Surfaces

April 1, 2007, 23:13 by Calle
[loading]
-->
Sometimes you want to take a photo of your game area; when level complete and things like that. Or perphaps you are creating a paint-program and you will most certainly want to use a screenshot rather than writing pixel by pixel to a file. Well, sometimes a screenshot won't do either, at least not screen_save() and screen_save_part() - because those functions are limited to what you see only... and sometimes what you see in not the entire picture. If you have a large drawing area for an example, this will become a problem. How do you do to cover the entire drawing area with one image, then? Well, with surfaces this becomes easy. Surfaces is also one of the more missunderstood mechanisms in Game Maker and therefore I am surprised I have not been writing anything about it earlier.

surface = surface_create(width,height);
surface_set_target(surface);


This is just an example of how simple it is to set up surfaces and put focus onto them. And with this comes an amazing amount of possibilities:
> You only need to draw things once on a surface; which is good for speed issues...
> You can stretch and manipulate a surface such as would it be a sprite
> You can draw it tiled, which is highly useful for room decorations and more, yet again something that would be devastating to the memory if done with draw functions

And then there is one more great opportunity that will solve our problem, with which this article begun. You can save parts from a surface! This does not neccesarily mean that the sprite or picture or whatever you try to screenshot has to be in view, or even in the room. You can save it anyway, as long as the sprite is drawn onto the surface and the surface exists (anywhere...). Here is the function:
surface_save_part(id,fname,x,y,w,h)

For a complete overview of surfaces I would suggest the manual. There is no better.

Thanks for reading :)

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games