FMX.SimplePhysics Sample
This sample demostrates how to use the Box2D physics engine with FireMonkey controls in Delphi applications.
Contents
Location
You can find the FMSimplePhysics sample project at:
- Start | Programs | Embarcadero RAD Studio Berlin | Samples and navigate to:
Object Pascal\Multi-Device Samples\Physics\FMXSimplePhysics
- Subversion Repository:
Description
The FMSimplePhysics sample shows you how to create a simulation based on the laws of the physics using Box2D. This sample simulates the effect of gravity applied to the FireMonkey controls of the form. Therefore, the controls of the form fall from the top of the form to the bottom. Moreover, the controls bounce and collide with each other when they reach the bottom of the form.
How to Use the Sample
- Navigate to the location given above and open
FMSimplePhysics.dproj
. - Select the target platform.
- Press F9 or choose Run > Run.
- Interact with the sample:
- Click the Drop button to start the physics simulation. All the components on the form fall to the bottom.
- Click Reset to reset the form. Place all the components in a random position along the top of the form.
Files
File in Delphi | Contains |
---|---|
|
The project itself. |
|
The main form. |
|
The main unit. |
|
The basic simulation unit. |
|
The unit that provides Box2D features to the basic simulation unit. |
|
The unit that defines the simulation class implemented in this sample. |
|
The unit that implements a Helper class of TControl. |
Classes
TFormFmxPhysics is the main form that represents the main window of the sample. It contains the following components:
- A TToolBar object called ToolBar1 that contains the following components:
- A TButton object with the Text property set to
Button
. - A TCheckBox object with the Text property set to
CheckBox
. - A TPanel object called Panel1 that contains the following components:
- A TLabel object with the Text property set to
Panel
. - Two TSpeedButton objects.
- A TLabel object with the Text property set to
- A TProgressBar object.
- A TRadioButton object.
- Two TScrollBar objects.
- A TComboBox object.
- A TLabel object with the Text property set to
I'm a label
. - A TEdit object with the Text property set to
some text
. - A TTrackBar object.
Implementation
When you run the application, the form of the sample displays all the controls listed above. The sample implements an OnClick event for each of the following buttons:
- Drop - the event of this button briefly animates the FireMonkey components of the form. This event uses Box2D features to simulate the effect of gravity applied to the controls of the form.
- Reset - the event of this button resets the form. Therefore, all the components of the form are placed in a random position along the top of the form.
Uses
- FMX.StdCtrls.TToolBar
- FMX.StdCtrls.TButton
- FMX.StdCtrls.TCheckBox
- FMX.StdCtrls.TPanel
- FMX.StdCtrls.TLabel
- FMX.StdCtrls.TSpeedButton
- FMX.StdCtrls.TProgressBar
- FMX.StdCtrls.TRadioButton
- FMX.StdCtrls.TScrollBar
- FMX.ListBox.TComboBox
- FMX.Edit.TEdit
- FMX.StdCtrls.TTrackBar
See Also
Samples
- Box2D Hello sample
- Box2D TestBed sample