1 unit utest4; 2 3 {$mode objfpc}{$H+} 4 5 interface 6 7 uses 8 Classes, SysUtils, BGRABitmap, BGRABitmapTypes, Graphics, utestpacrect; 9 10 type 11 { TTest4 } 12 13 TTest4 = class(TTestPacRect) 14 protected 15 virtualScreen: TBitmap; 16 public 17 constructor Create; 18 destructor Destroy; override; 19 procedure OnPaint(Canvas: TCanvas; Left,Top,Width,Height: Integer); override; 20 end; 21 22 implementation 23 24 { TTest4 } 25 26 constructor TTest4.Create; 27 begin 28 inherited Create; 29 Name := 'TBGRABitmap.Draw(Bitmap). Non-flickering pacmans walking with a rectangle. Rectangle opacity depends on the rendering capacities of BGRABitmap on TBitmap.'; 30 virtualScreen := nil; 31 end; 32 33 destructor TTest4.Destroy; 34 begin 35 virtualScreen.Free; 36 inherited Destroy; 37 end; 38 39 procedure TTest4.OnPaint(Canvas: TCanvas; Left,Top,Width, Height: Integer); 40 var i: integer; 41 begin 42 if backgroundImg = nil then exit; 43 44 if (virtualscreen <> nil) and ((virtualscreen.width <> width) or (virtualscreen.Height <> height)) then 45 FreeAndNil(virtualScreen); 46 47 if virtualscreen = nil then 48 begin 49 virtualscreen := TBitmap.Create; 50 virtualscreen.width := Width; 51 virtualscreen.Height := height; 52 end; 53 54 //draw background opaque on bitmap canvas 55 backgroundImg.Draw(virtualScreen.Canvas,0,0,true); 56 57 //draw sprites transparent on bitmap canvas 58 for i := 0 to high(pacLoc) do 59 pacImg[numPacImg].Draw(virtualscreen.Canvas,pacLoc[i].x,pacLoc[i].y,false); 60 61 //draw virtualscreen as TBitmap 62 Canvas.Draw(Left,Top,VirtualScreen); 63 end; 64 65 end. 66