|  | 
 
So you've used Blitz2D and Blitz3D, you know the basic commands, but you've now got BlitzPlus and don't know where to start. It was supposed to be amazingly fast but whatever you write just seems to crash or doesn't work, or you can't close the window? We've all been there, so I've written this article to help Blitz+ newcomers get started quickly. 
When big difference that Blitz+ handles the program flow instead of previous Blitz versions is in its Events. Every Windows program has events. When you click a button, drag a window, click the X to close it, resize the window... all of these require Windows to update information regarding the window and to redraw it in some form or other. If Blitz hogged the CPU entirely then Windows would never get a look in and it would freeze. :( 
So instead we've got something called WaitEvent(). WaitEvent() basically tells Blitz to pass the CPU back to Windows until it's needed, or rather, until the next "event" occurs. If you have a look in the command reference under WaitEvent, you will find among others, the following events:
 
There are others, but these are the most important and the ones you're going to need to remember. $803 is by far the most important because it is the event that occurs when the user clicks the X button on a window. If you want your app to close, you need to do something when this happens, otherwise the window won't disappear!
Ok so we know what the events are. Now we need to put them into action. Well, let's first make a window and set up a skeleton for a simple Blitz+ application.. 
 
If you copy that into BlitzPlus, it should do something impressive like make a window with a black canvas, which doesn't really do a lot but professes to the world your l33tness and then waits for you to close it. You'll notice also the empty menu bar and status bar there, and that the window is resizable. Well those are the defaults for any window. 
But enough of that. We've created a window and a graphics canvas. Now what? We need to get Blitz+ to update the game and draw it, but also have all that fancy frame-limiting stuff that we used to do in previous versions. While the program is in WaitEvent() mode, it's halted so we need to call upon the awesome powers of the TIMER TICK event. ($4001) 
To do timer ticks, you first of all create a timer. And, then that's it. Every time the timer ticks over, a TIMER TICK event is called and you can use it to update your game. Voila, frame-limiting. But wait, what if your PC is so slow that the timer ticks more than once. Well, EventData() contains the total number of ticks that have occured in the timer so you gotta use a little variable. Like so: 
 
And there you have it, an ominous message of terror that runs the same speed on the PC of every mortal that dares to run it. 
Well that's the backbone of frame-limiting and events for games in BlitzPlus. Just a few notes on how to speed up your games further still, and some things to consider: 
 For a printable copy of this article, please click HERE. 
 This site is Copyright© 2000-2004, BlitzCoder. All rights reserved.   |