delphix does NOT work with borland kylix
Badly Drawn Boy
In this tutorial we'll get back to where we should have started - the DXDraw component. This is the main component that DelphiX has, allowing us to simply display our game on the form, and in full-screen. It allows us to get rid of flicker very easily as well, and we'll take a look at how previous examples can have their flicker removed. We'll also be introducing three other components, namely the DXImageList, DXSpriteEngine and DXTimer components.
The DXDraw Component
To set up the DXDraw component in the first place, we need do very little work. Place a DXDraw component on the form, and set it's Align property to alClient. This will stretch out the DXDraw component's canvas to cover the whole of our form. That's kind of it. If you want to make this full screen we simply set the doFullScreen property (found in the Options area of the Properties list), to true and choose an appropriate resolution from the Display property. We also need to set the BorderStyle property of our actual form to bsNone which will stop our window bar showing in full screen mode. You should also enter the following code in the OnKeyDown event of our form:
if key = 27 then close;
This will have the effect of letting us quit our program by simply pressing the ESC key (key number 27). Of course, presumably you want a little more from this tutorial than a black canvas, which is what you'd get if you ran this 'program' now. To actually place something on this black void of despair though is, luckily, nearly as simple. Before we can continue though, we have to introduce another component - DXImageList.
The DXImageList Component
We'll shortly be discussing a little bit about the use of the normal ImageList component, but things are more or less the same with the DXImageList component really, and this is what we will be using here.
This component allows us to store all images which we will use in our games in one handy component. Everything from backgrounds through to sprites should be placed in here for access from our program. Before we continue though, set the DXDraw property of the DXImageList to DXDraw1. This links the images up correctly so that they can be displayed on our DXDraw surface.
The Dialog Box for the Items entry of the DXImageList component
We're now going to place the 'Ye Olde Delphi Game Developer' logo in our image list for displaying on our screen, to introduce the component. To do this, we just need to click on the button to the right of the Items property of our ImageList, to bring up a dialog box (as shown on the right). You can then click on the left side button to create a new image entry. Then just select the relevant file from the Picture property and before you close the dialog, give it a name such as 'Logo'.
If you add the following code to the MouseDown procedure of your form, you'll find yourself with a program that places a copy of the logo wherever you click on the screen:
Not very interesting in itself, but what we are doing here is taking the first image in our image list and displaying it on the surface of our DXDraw's surface, in this case at the X and Y co-ordinate of the mouse click. We then have to call the flip because up until this point, everything we have done is in a buffer not visible. By calling flip, we move this image into view on our DXDraw's surface. We'll come back to this in a second, but let's move on and introduce the TDXSpriteEngine component and do some interesting things related to animating and moving a character around the screen, in part 2.