FMX.SimplePhysics Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demostrates how to use the Box2D physics engine with FireMonkey controls in Delphi applications.


You can find the FMSimplePhysics sample project at:

  • Start | Programs | Embarcadero RAD Studio Alexandria | Samples and navigate to:
    • Object Pascal\Multi-Device Samples\Physics\FMXSimplePhysics
  • Subversion Repository:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.


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

  1. Navigate to the location given above and open FMSimplePhysics.dproj.
  2. Select the target platform.
  3. Press F9 or choose Run > Run.
  4. 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.


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.


TFormFmxPhysics is the main form that represents the main window of the sample. It contains the following components:


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.


See Also