Forum > Graphics

timage sprite animation and png transparency

(1/1)

jw:
because this was hard for me I'll go ahead and post the code


1st png's with transparent backgrounds are supported just not directly by a timage why? I don't know.  First you've got to define a TCustomBitmap and create a TPortableNetworkGraphic then assign this to a timage.

2nd timagelists hold array's of images of the same height and width.  The default height and width of
timagelist is 16 x 16 if you load a bigger image into it without setting timagelist height
and width it will overload the timagelist and it will do weird stuff.  

below is code that throws 4 animating sprites on the screen
useing timage timagelist and a timer.

if I could post the project I would the timiagelist is loaded with 0-8 images or 9 images.  It's a rotating snowflake broken down from a free animted gif and converted to transparent png's





--- Code: ---unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ExtCtrls;


type

  { TForm1 }

  TForm1 = class(TForm)
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    ImageList1: TImageList;
    Timer1: TTimer;
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  Img: TCustomBitmap;
  count: integer;


implementation

{ TForm1 }








procedure TForm1.FormCreate(Sender: TObject);

begin

img:=TPortableNetworkGraphic.Create;



end;

procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  img.Free;
end;






procedure TForm1.Timer1Timer(Sender: TObject);
begin

  count:=count + 1;
  if count > 8 then count :=0;
  ImageList1.GetBitmap(count, img);
  Image1.Picture.Assign(img);
  Image2.Picture.Assign(img);
  Image3.Picture.Assign(img);
  Image4.Picture.Assign(img);

end;

initialization
  {$I unit1.lrs}

end.
                                                        


--- End code ---

GordonShumway:
Thank you, man I was going crazy trying to figure out why it wasn't working properly. :D THANK YOU!

Gintas:
I wonder does it works without flickering and in Lazarus sprites example :)

Leledumbo:

--- Quote ---I wonder does it works without flickering and in Lazarus sprites example
--- End quote ---
That example only requires DoubleBuffered to be set true to avoid flickering.

Navigation

[0] Message Index

Go to full version