Mega Code Archive

 
Categories / Delphi / VCL
 

TNumberLabel (component)

Title: TNumberLabel (component). Question: N/A Answer: Most arcade games (old style) have level's which end with a score screen, the score is then calculated and added to your score, this done by adding the score for each extra second or extra bounce to a basic score giving it the appearance of a racing speedometer, instead of giving the end result at once. This article is about a component TNumberLabel that mimic this way of showing numbers. The component is descendent from TCustomlabel and has an internal timer. I didn't publish the Caption property of TCustomLabel, but it could be useful in some cases. The component has a property called Number, which will be the number you want to show, this is stored in FNumber, FDest is the difference between the new value and the old. the timer OnTimer event looks like this: if FDest then begin Inc(FDest); Caption := (IntToStr(FNumber + Abs(FDest))) end; if FDest 0 then begin Dec(FDest); Caption := (IntToStr(FNumber - FDest)) end; if FDest = 0 then begin Timer.Enabled := False; end; There is a second property called Interval, which expose the interval property of the timer. The full source is attached to this article.