Files
QtGameMaker/help/files/405_12_repaint.html
T

111 lines
3.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Repainting the Screen</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body background="images/back.gif">
<!--START-->
<h3>Repainting the screen</h3>
Normally at the end of each step the room is repainted on the screen. But in rare
circumstances you need to repaint the room at other moments. This happens when your
program takes over the control. For example, before sleeping a long time a repaint might
be wanted. Also, when your code displays a message and wants to wait for the player to
press a key, you need a repaint in between. There are two different routines to do this.
<p>
<blockquote>
<tt><b>screen_redraw()</b></tt>
Redraws the room by calling all draw events.<br>
<tt><b>screen_refresh()</b></tt>
Refreshes the screen using the current room image (not
performing drawing events).<br>
</blockquote>
<p>
To understand the second function, you will need to understand more fully how drawing
works internally. There is internally an image on which all drawing happens. This image is
not visible on the screen. Only at the end of a step, after all drawing has taken place,
is the screen image replaced by this internal image. (This is called double buffering.)
The first function redraws the internal image and then refreshes the screen image. The
second function only refreshes the image on the screen.
<P>
Now you should also realize why you cannot use drawing actions or functions in other
events than drawing events. They will draw things on the internal image but these won't be
visible on the screen. And when the drawing events are performed, first the room
background is drawn, erasing all you drew on the internal image. But when you use <tt>
screen_refresh()</tt> after your drawing, the updated image will become visible on the
screen. So, for example, a script can draw some text on the screen, call the refresh
function and then wait for the player to press a key, like in the following piece of code.
<p>
<blockquote>
<pre>
{
draw_text(room_width/2,100,'Press any key to continue.');
screen_refresh();
keyboard_wait();
}
</pre>
</blockquote>
<p>
Please realize that, when you draw in another event than the drawing event, you draw
simply on the image, not in a view! So the coordinates you use are the same as if there
are no views.
Be careful when using this technique. Make sure you understand it first and realize that
refreshing the screen takes some time.
<p>
When you are drawing the room yourself it can be useful to NOT let it be drawn automatic
at all. For example, you might want to draw the room only every 5 steps. You can use the
following functions for this:
<p>
<blockquote>
<tt><b>set_automatic_draw(value)</b></tt>
Indicates whether to automatically redraw the room (true, default) or not (false).<br>
</blockquote>
<p>
Finally there is a function with which you can set whether to synchronize the drawing with
the refresh frequency of the monitor:
<p>
<blockquote>
<tt><b>set_synchronization(value)</b></tt>
Indicates whether to synchronize the drawing with the refresh frequency of the monitor.<br>
</blockquote>
<p>
You can also force a wait for the next vertical synchronization using the following function:
<p>
<blockquote>
<tt><b>screen_wait_vsync()</b></tt>
Waits for the next vertical synchronization of the monitor.<br>
</blockquote>
<!--END-->
</body>
</html>
<!-- KEYWORDS
redrawing the screen
refreshing the screen
automatic drawing
synchronization
screen_redraw()
screen_refresh()
screen_wait_vsync()
set_automatic_draw()
set_synchronization()
-->