Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: jw on March 19, 2010, 05:34:05 pm

Title: timage sprite animation and png transparency
Post by: jw on March 19, 2010, 05:34:05 pm
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: [Select]
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.
                                                        

Title: Re: timage sprite animation and png transparency
Post by: GordonShumway on May 04, 2010, 02:22:42 pm
Thank you, man I was going crazy trying to figure out why it wasn't working properly. :D THANK YOU!
Title: Re: timage sprite animation and png transparency
Post by: Gintas on May 26, 2010, 01:10:33 pm
I wonder does it works without flickering and in Lazarus sprites example :)
Title: Re: timage sprite animation and png transparency
Post by: Leledumbo on May 27, 2010, 05:11:33 am
Quote
I wonder does it works without flickering and in Lazarus sprites example
That example only requires DoubleBuffered to be set true to avoid flickering.
TinyPortal © 2005-2018