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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Repainting the screen<br />

Normally at the end of each step the room is repainted on the screen. But in rare<br />

circumstances you need to repaint the room at other moments. This happens when your<br />

program takes over the control. For example, before sleeping a long time a repaint might be<br />

wanted. Also, when your code displays a message and wants to wait for the player to press a<br />

key, you need a repaint in between. There are two different routines to do this.<br />

screen_redraw() Redraws the room by calling all draw events.<br />

screen_refresh() Refreshes the screen using the current room image (not<br />

performing drawing events).<br />

To understand the second function, you will need to understand more fully how drawing works<br />

internally. There is internally an image on which all drawing happens. This image is not visible<br />

on the screen. Only at the end of a step, after all drawing has taken place, is the screen image<br />

replaced by this internal image. (This is called double buffering.) The first function redraws the<br />

internal image and then refreshes the screen image. The second function only refreshes the<br />

image on the screen.<br />

Now you should also realize why you cannot use drawing actions or functions in other events<br />

than drawing events. They will draw things on the internal image but these won't be visible on<br />

the screen. And when the drawing events are performed, first the room background is drawn,<br />

erasing all you drew on the internal image. But when you use screen_refresh() after your<br />

drawing, the updated image will become visible on the screen. So, for example, a script can<br />

draw some text on the screen, call the refresh function and then wait for the player to press a<br />

key, like in the following piece of code.<br />

{<br />

draw_text(room_width/2,100,'Press any key to continue.');<br />

screen_refresh();<br />

keyboard_wait();<br />

}<br />

Please realize that, when you draw in another event than the drawing event, you draw simply<br />

on the image, not in a view! So the coordinates you use are the same as if there are no views.

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

Saved successfully!

Ooh no, something went wrong!