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

Floating Panel Animation Delphi FiremonkeyRad 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
{ Private declarations }
pnl: TPanel;
lbl: TLabel;
public
{ Public declarations }
procedure DoClick(Sender: TObject);
end;

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

procedure TfrmMain.FormCreate(Sender: TObject);
begin
//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;

end;
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);
begin
pnl.AnimateFloat('Position.y', - pnl.Height, 1.0);
end;

Head over and see the other properties of TAnimateFloat.

close

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

Related posts
AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

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

DelphiIDEShowcaseWindows

Ryzen 9 5950x: One Billion Lines Of Delphi Code Compiled In ~5 Minutes On 16 Cores

DelphiFiremonkeyIDEIOSOSXWindows

DelphiCon 2020 FireMonkey Sessions Available Starting November 19

AndroidC++BuilderDelphiDemoFiremonkeyWindows

Powerful Commercial Gorilla3D Framework Upgraded For Delphi FireMonkey On Windows And Android

Sign up for our Newsletter and
stay informed

Leave a Reply