A Quick and Dirty VCL Sprite Engine - Part I
By: John Ray Thomas
Abstract: Draw an image to a specific position and region.
Draw an image to a specific position and region.
The simple overview of the steps of placing images on a drawing area with Windows API is
Using the VCL these steps become
- load a bitmap (.bmp) file as a device independant bitmap,
- associate it to an in-memory HDC to become a device-dependant bitmap,
- handle a WM_PAINT message and use BitBlt to draw it to an in-view HDC.
These steps look like this in VCL code.
- create a TBitmap object and call it's member function LoadFromFile or LoadFromResource,
- which automatically creates a device-dependant bitmap to the in-memory HDC, TBitmap::Canvas,
- place it on the TForm at a specific postion by calling the TForm's Canvas::Draw function during an OnPaint event.
Graphics::TBitmap *bmp = new Graphics::TBitmap();
This places the top-left pixel of the bitmap at the location (0,0) on the main forms Canvas (our visible HDC) and covers the rectangular region with the image from (0,0) to (bmp->Left, bmp->Bottom).
Published on: 2/4/2000 12:00:00 AM
Server Response from: ETNASC02