08.11.2012 Views

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

In certain situations you might want to paint not directly on the screen but on a canvas that<br />

can then later be used to paint things on the screen. Such a canvas is called a surface. For<br />

example, you want to let the user draw on the screen. The paint should not be drawn on the<br />

screen (because it will be removed each next step), but instead you want to draw it on a<br />

separate surface that is copied onto the screen in each step. Or you want to use a texture that<br />

changes over time.<br />

Surfaces make this all possible. They are actually rather simple to use. You first create a<br />

surface. Next you indicate that further drawing should happen on this surface. From that<br />

moment on all drawing functions operate on the surface. Once you are done you reset the<br />

drawing target and further drawing happens on the screen again. You can draw the surface on<br />

the screen in many different ways or use it as a texture. There are though a few things you<br />

must be aware of. See the remarks at the end.<br />

The following functions exist to deal <strong>with</strong> surfaces<br />

surface_create(w,h) Creates a surface of the indicated width and height.<br />

Returns the id of the surface, which must be used in all further calls. Note that<br />

the surface will not be cleared. This is the responsibility of the user. (Set it as<br />

a target and call the appropriate clear function.)<br />

surface_free(id) Frees the memory used by the surface.<br />

surface_exists(id) Returns whether the surface <strong>with</strong> the indicated id<br />

exists.<br />

surface_get_width(id) Returns the width of the surface.<br />

surface_get_height(id) Returns the height of the surface.<br />

surface_get_texture(id) Returns the texture corresponding to the<br />

surface. This can be used to draw textured objects <strong>with</strong> the image of the<br />

surface.<br />

surface_set_target(id) Sets the indicated surface as the drawing target.<br />

All subsequent drawing happens on this surface. It resets the projection to<br />

simply cover the surface.<br />

surface_reset_target() Resets the drawing target to the normal screen.<br />

surface_getpixel(id,x,y) Returns the color of the pixel corresponding to

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!