Real Time Scaleable Sprites 
Components
for
Borland Delphi
Copyright 1995 by:
Marek A. Chmielowski  
All rights reserved - see disclaimer  at the end of this document.


Description
Real Time Scaleable Sprites for Borland's Delphi consists of two 
components:
1 animation background component - MChSpriteBgr  
2 sprite component - MChSprite  
Animation background and transparent sprites (up to 100) are created as 
instances of corresponding components by double clicking on Delphi 
component palette and by selecting proper image (e.g. bitmap) with 
Object Inspector property editor (Picture Editor). All initialisation is handled 
by components themselves. Instance of MChSprite can be moved on 
instance of MChSpriteBgr with single method call e.g. 
MChSprite1.SprGo(From, Dest, AtTime). Sprite position is determined by 
real time clock and is independent on computer and graphic cart 
performance (slow cart results in jetted movements). Sprites are 
implemented as autonomous objects and support transparent colour, 
collision, Z-order (overlapping), Z-order dynamic change, sprite scaling, 
dynamic scale change, image flipping, linear movement and movement 
along curve. Sprites can respond to mouse pointer and can be drag with 
mouse to new position. Sprite movement can be synchronised with sound 
effects.
Source code for components and demo program is provided in PKzip 
compressed package  .
These components and source code is FREE  for non-profit applications - 
see copyright information and disclaimer  at the end of this document. 


Package
Source  code for Sprites components and demo  programs (also 
executable  for IBM-PC and Windows 3.1) is in PKzip compressed 
package sprites.zip  . To get sprites.zip  package from: 
http://sunsite.icm.edu.pl/archive/delphi/ftp/freeware/sprites.zip  double 
click on any "sprites.zip  " name and then on highlighted http external link.
PkZip package sprites.zip  
contains:
  Sprites.htm This file  
  Spritest.txt Text only version of this file  (it is NOT nicely formatted)
  Sprites.txt Note for BBS operator
  SprDemo2.exe Compiled colliding sprites demo
  SprDemo3.exe Compiled mouse aware demo
  MChSpBg.pas source code for background component
  MChSprt.pas source code for sprite component
  SpritesH.hlp help file for background component
  SpritesH.kwf keyword file for background component
  SprDemo0.dpr project source code for very simple demo
  SprDemo1.dpr project source code for simple demo
  SprDemo2.dpr project source code for colliding sprites demo
  SprDemo3.dpr project source code for mouse aware demo
  SprDmSB2.dpr project source code for colliding sprites demo using 
Sound Blaster
  UntDemo0.pas unit source code for very simple demo
  UntDemo0.dfm form file for very simple demo
  UntDemo1.pas unit source code for simple demo
  UntDemo1.dfm form file for simple demo
  UntDemo2.pas unit source code for colliding sprites demo
  UntDemo2.dfm form file for colliding sprites demo
  UntDemo3.pas unit source code for mouse aware demo
  UntDemo3.dfm form file for mouse aware demo
  UntDmSB2.pas unit source code for colliding sprites demo using 
Sound Blaster
  UntDmSB2.dfm form file for colliding sprites demo using Sound 
Blaster
To unpack type on IBM-PC compatible computer type:
pkunzip sprites.zip  


Demos
You can run SprDemo2.exe  and SprDemo3.exe  demos on IBM-PC 
compatible computer from Windows 3.1 without installing components 
(you can run them without Delphi at all). Do NOT load their source code 
into Delphi before installing  Sprites components. Demo using Sound 
Blaster compatible cart: SprDm2SB.dpr  is provided in source code 
version only, because I do not have rights to distribute samples of sound 
files provided with my Sound Blaster card. Please edit filename property of 
multimedia components in SprDmSB2.dfm  form to select your sound 
files - see Delphi help about TMultimediaComponent and it's properties. 
For Sound Blaster 16 I have used s_8_22.wav and jazz.mid for 
MediaPlayer 1 and 2 respectively.
Both executables are running fine on my desktop PC and on my laptop, 
however they are crashing at my PC at work. I suspect that Windows 
driver is incompatible with Delphi expectation, but I do not intent to bother. 
If demos (executables) are not working and this will not discourage you 
from using this software (it should) just tray install components and 
recompile demo source code. 


Installing Sprites Components
Read first Delphi User's Manual - page 68.
My comments:
1 First of all backup COMPLIB.DCL - it should be in delphi/lib 
directory. DO NOT be sorry if compilation will go wrong - I 
WARNED you. (Do not panic either - you can get original 
COMPLIB.DCL from Borland's distribution disk(s).)
2 Copy mchspbg.pas  and mchsprt.pas  into your non-Borland 
components directory (It is nice to have one and not mess 
original components with freeware junk e.g. 
Real Time Scaleable Sprites  )
3 From Delphi IDE - select Options|Install Components, Add, 
Browse - and double click on mchspbg.pas  then on 
mchsprt.pas  
4 Hit OK to install new Components - They should appear on your 
'Sample' palette


Testing
Run SprDemo2.exe  first - you can do this before installing components 
into Delphi.
If you like what you have seen - instal components  .
Test SprDemo1 source code  first:
Open Project SprDemo1.dpr  , than open Form1 and from Object 
Inspector:
1 In MChSpriteBgr1 edit field "Picture" - click on three dots - then 
select your bitmap as background (do not select to large one first 
- you may run into memory problem as several copies of 
background image will be made)
2 In MChSprite1 and MChSprite2 edit field Bitmap -- click on three 
dots - then select your bitmap as sprite (pick up really small one 
- see in Delphi/images/splash/colors16)
3 In MChSprite1 and MChSprite2 edit SprTrColor - pick up colour 
to be transparent
Run SprDemo1 with yours background and yours sprites
From now you are on your own - tray SprDemo2.dpr  and then 
SprDemo3.dpr  . Read help file  and look at the code UntDemo0.pas  , 
UntDemo1.pas  , UntDemo2.pas  , and UntDemo3.pas  . If you have 
Sound Cart look also at UntDm2SB.pas  .
Send me e-mail  if you like or hate this package  .


Installing the Help Files
See Delphi Component Writer's Guide page 80.
If you have trouble in understanding Borland's documentation (I had) you 
can use SpritesH.hlp  directly from Windows:
Associate extension .hlp with WinHelp and just double click on spritesh.hlp  
(You can read Sprites help but there is no link from Delphi). You can also 
create New program Item WinHelp spritesh.hlp  from program Manager.
To have help available from Delphi IDE on pressing F1 (it should display 
help when cursor is on Component Palette, if Sprite or Sprite Background 
component are selected on Form, or if TMChSprite or TMChSpriteBgr 
words are selected in source editor) is more complex:
  copy spritesh.kwf  to delphi/help and spritesh.hlp  to delphi/bin
  run delphi/help/helpinst.exe (there is an icon in Delphi group):
1.1 Open delphi/bin/delphi.hdx
1.2 Press "+" and select spritesh.kwf
1.3 Press "Save"


References and Comments About 
Used Programming Technique 
Real Time Scaleable Sprites have been implemented using autonomous 
object approach as opposite to frame based technique  . Movement, 
visibility, and scale of each sprite is determined only by sprite itself (i.e. by 
it's properties). This way only single image for sprite is required and there 
is no need for huge filmstrip bitmaps required by frame animation. 
Background component  is resolving conflicting request from sprites  (e.g. 
request from two sprites to be display in the same place) and synchronise 
screen update in flicker free fashion.
Sprites components have been developed on the base of excellent book  
about animation in Windows by Nigel Thompson. The only drawback I 
have found in this book are programming examples based on non-
structured, non-modular, and with messy syntax C++ computer slang.
Animation techniques in Win32, by Nigel Thompson, Microsoft 
Programming Series, Microsoft Press.
If you are allergic to C++ (I am) you can find Delphi Object Pascal 
examples illustrating basic techniques of using transparent bitmaps on 
newsgroup comp.lang.pascal:
Very simple and concise:
Transparent Bitblt - by Bryan Zarnett
http://sunsite.icm.edu.pl/archive/delphi/ftp/from_news/9.txt  
Somewhat more complex and showing very strong C heritage:
Transparent Bitmap - by Michael Vincze
http://sunsite.icm.edu.pl/archive/delphi/ftp/from_news/7.txt  
For easy to understand Delphi example of simple object based 
animation see very nice example:
Flickerless Sprite Animation - by David R. McDermitt in freeware section
http://sunsite.icm.edu.pl/archive/delphi/ftp/freeware/copyrect.zip  
Example of Delphi frame based animation component can be found in 
shareware section
Animation component by Dare Baldwin (free for freeware writers)
http://sunsite.icm.edu.pl/archive/delphi/ftp/shareware/animate.zip  


Copyright Information and 
Disclaimer 
These components and source code is FREE for non-profit applications. 
This package may be copied and distributed freely providing that it is not 
modified, no fee is charged, and it is not used by package for which a 
charge is made.
Use this package entirely on your own risk as no warranty is provided. 
Even if this software will cause the whole universe to blow I will be 
responsible only to God.
(Will you DARE to press Super Nova button in SprDemo3 now.)
Please do NOT distribute components or source code if you altered them 
-
EVEN IF THIS IS ONLY BUG CORRECTION.
Let me  know about the problem and the solution and I will implement it in 
the next
version (may be it will be the next version). Also suggestions are 
appreciated.
If you would like to use this components for shareware or commercial 
application
please contact me first by mail  :
My (Marek Chmielowski) e-mail:
on Compuserve: 76360,2775
on Internet: 76360,2775@compuserve.com
Mail:
Marek Chmielowski
5/56 Kozia St.
Warsaw 00-070
Poland
(48) (22) 226-01-85
or
Marek Chmielowski
10005 Broad St.
Bethesda, MD 20814
USA
(301) 897-5266 

