Draw me a picture I don't get it!

The GameAPI screen is represented by a series of pixels organized on an x and y axis. Position (0, 0) is the top left of the screen and (240, 320) is the bottom right for the typical QVGA display on a PocketPC and (480, 640) is the bottom right for a typical VGA display device.

Drawing to the screen is very simple with the GameAPI, you just need to know where to place the drawing code. Since the first part of our series of articles on the GameAPI talked about a basic code template to create a GameAPI program, we need to focus a little more on the WM_PAINT event here. The WM_PAINT event is called every frame the GameAPI needs to draw to the screen. The WM_PAINT is placed in the game procedure code, like this:

func GameProc(hWnd$, Msg$, wParam$, lParam$)
case (Msg$)
WM_PAINT:
G_Clear(0);
end;
end;

When you initialize the GameAPI you pass the GameProc pointer to the InitGameApiEx() function. PPL will then use this function to trigger custom events like WM_PAINT, WM_TIMER and WM_COLLIDE.

InitGameAPIEx(h$, &GameProc, 240, 320, false, 5, 60);

Inside the WM_PAINT code you can put any type of drawing code you want, like g_clear(0) to clear the screen with a color you like, g_textout() to draw informative text and g_fillrect() to draw a rectangle. PPL comes loaded with a ton of drawing functions. PPL clears the screen in black by default if no WM_PAINT event is defined.

What if you want to draw something on the screen outside the WM_PAINT event code? It’s easy, but you need to follow some guidelines. You need to prepare the screen to be drawn to and when done you need to update the screen. Here is simple code to draw a rectangle, wait 5 seconds and then return to normal drawing of the screen either by triggering the WM_PAINT code or by simply clearing the screen with black.

g_beginscene;
g_fillrect(10, 10, 100, 100, g_rgb(100, 100, 100));
g_update;
delay(5000);

Be careful not to call g_beginscene() without calling a corresponding g_update(). Follow this rule and you will never have any problems.