Use delphix to display the image and use the image as the background

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.