Recent

Author Topic: timage sprite animation and png transparency  (Read 9714 times)

jw

  • Full Member
  • ***
  • Posts: 126
timage sprite animation and png transparency
« 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.
                                                        

« Last Edit: March 19, 2010, 05:38:58 pm by jw »

GordonShumway

  • Newbie
  • Posts: 6
Re: timage sprite animation and png transparency
« Reply #1 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!

Gintas

  • Jr. Member
  • **
  • Posts: 71
    • Developer's Diary
Re: timage sprite animation and png transparency
« Reply #2 on: May 26, 2010, 01:10:33 pm »
I wonder does it works without flickering and in Lazarus sprites example :)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: timage sprite animation and png transparency
« Reply #3 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