This code is for delphix. You can download it on www.2ccc.com.
Steps:
(1) place the following space on the main form of the newly created Project: dximagelist, dxdraw, dxspriteengine, dxtimer
(2) set the image to be displayed: dximagelist-> items-> Create a New tpicturecollectionitem and name it backgroundpicture-> select the picture attribute of the item-> select an image (in BMP format );
The following code is used:
Unit unit1;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, dxclass, dxdraws, dxinput, dxsprite, extctrls;
Type
Tform1 = Class (tdxform)
Pnlplan: tpanel;
Dxdraw1: tdxdraw;
Dxspriteengine1: tdxspriteengine;
Dxtimer1: tdxtimer;
Dximagelist1: tdximagelist;
Procedure dxdraw1initialize (Sender: tobject );
Procedure dxdraw1finalize (Sender: tobject );
Procedure formcreate (Sender: tobject );
Procedure dxtimer1timer (Sender: tobject; lagcount: integer );
Private
{Private Declarations}
Procedure drawbackgroundpicture;
Public
{Public declarations}
Backgroundsprite: tbackgroundsprite; {background image of the game}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Procedure tform1.dxdraw1initialize (Sender: tobject );
Begin
Dxtimer1.enabled: = true;
End;
Procedure tform1.dxdraw1finalize (Sender: tobject );
Begin
Dxtimer1.enabled: = false;
End;
Procedure tform1.drawbackgroundpicture;
Begin
Dximagelist1.items. makecolortable;
// Update the system palette
Dxdraw1.colortable: = dximagelist1.items. colortable;
Dxdraw1.defcolortable: = dximagelist1.items. colortable;
Dxdraw1.updatepalette;
// Set the image to be displayed and used as the background
Backgroundsprite: = tbackgroundsprite. Create (dxspriteengine1.engine );
With tbackgroundsprite (backgroundsprite) Do
Begin
Setmapsize (1, 1 );
Image: = dximagelist1.items. Find ('backgroundture ');
// Picture level
Z: =-2;
// Tile
Tile: = true;
End;
End;
Procedure tform1.formcreate (Sender: tobject );
Begin
Drawbackgroundpicture;
End;
Procedure tform1.dxtimer1timer (Sender: tobject; lagcount: integer );
Begin
If not dxdraw1.candraw then exit;
// The following figure shows the background image.
Lagcount: = 1000 Div 60;
Dxspriteengine1.move (lagcount );
Dxspriteengine1.dead;
Dxdraw1.surface. Fill (0 );
Dxspriteengine1.draw;
Dxdraw1.flip;
End;
End.