A Quick and Dirty VCL Sprite Engine

By: John Ray Thomas

Abstract: This article explains how to create a simple sprite engine with the VCL.

A Quick and Dirty VCL Sprite Engine

by JT

The VCL TBitmap and TCanvas components can provide a solid framework for a sprite engine. TCanvas does a nice job encapsulating the Windows HDC and it's associated drawing functionality and TBitmap provides easy to use image management and transparency support.

A sprite engine has to do at least these things.

  1. Draw an image to a specific position and region.
  2. Draw a background image and foreground sprites without flicker.
  3. Allow a transparency color, to show the background around irregular shaped sprites.
  4. Move sprites to a new locations.
  5. Run through a series of images that comprise an animation cycle.
  6. Provide clipping against the world and other sprites.
A source code example can be downloaded from CodeCentral.

It is a C++Builder 4 project but the source can be used with any version of C++Builder. Here is a screenshot of the example application, "Tank".

Give it a test drive.



Server Response from: ETNASC01