Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodCode SnippetDelphiFiremonkeyIOSOSXWindows

Create Floating Animation With TAnimateFloat In Delphi Firemonkey

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Floating Panel Animation Delphi Firemonkey | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSRad Studio XE2 introduced FireMonkey animation effects. A list of these effects, their description, methods, properties, and events can be found here. For each animation effect, Embarcadero also provides code examples. For example, for the TFloatAnimation effect, Embarcadero has provided five different examples at the bottom of the page. The simplest of the demos demonstrates how to make a rectangle fade from its original color state to transparent. This should work cross platform on Android, IOS, OSX, and Windows.

However, below I have provided a simple demo of using the TAnimateFloat effect as well.  Unlike Embarcadero’s examples, this demo utilizes TFloatAnimation at runtime to make a “Hello World” Splash screen from a TPanel.

Start by creating two controls (pnl: TPanel & lbl: TLabel) in the main form’s class.
TForm1 = class(TForm)
Panel1: TPanel;
FloatAnimation1: TFloatAnimation;
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
{ Private declarations }
pnl: TPanel;
lbl: TLabel;
{ Public declarations }
procedure DoClick(Sender: TObject);

Add the following code to the form’s OnActivate and OnCreate events.
procedure TfrmMain.FormActivate(Sender: TObject);
pnl.AnimateFloat('Position.y', Self.Height div 4,  1.0);

procedure TfrmMain.FormCreate(Sender: TObject);
//create the panel
pnl:= TPanel.Create(self); pnl.Parent:= self;
pnl.Width:= ClientWidth div 2;
pnl.Height:= ClientHeight div 4;
pnl.Position.X:= (ClientWidth div 2) -(trunc(pnl.Width) div 2);
pnl.Position.Y:= - pnl.Height;
pnl.OnClick:= DoClick;

//create the label
lbl:= TLabel.Create(pnl);
lbl.Parent:= pnl;
lbl.Text:= 'Hello World';
lbl.TextAlign:= TTextAlign.taCenter;
lbl.Align:= TAlignLayout.alClient;

In order to make the Panel reverse directions and go the other way, we will add an OnClick event for the TPanel created at runtime.
procedure TfrmMain.DoClick(Sender: TObject);
pnl.AnimateFloat('Position.y', - pnl.Height, 1.0);

Head over and see the other properties of TAnimateFloat.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts

AutoBlogAI: FireMonkey Client To Leverage LLMs And Generative AI For Blogging


Unleashing Creativity With Song Writer AI: A Deep Dive


How To Build Stable Diffusion Text To Image Prompts


FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes

Sign up for our Newsletter and
stay informed

Leave a Reply