Box2D.Box2DHello

From RAD Studio Code Examples
Jump to: navigation, search

A "Hello World" example for the Box2D third party add-on.

Location

You can find the SurfSpotFinderApp sample project at:

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

Description

A "Hello World" example for the Box2D third party add-on.

The application uses the following controls:

  • Button1: Fires the Button1ClickHandler.
  • Memo1: Displays the output of the application.

How to Use the Sample

  1. Navigate to one of the locations given above and open FlatBox2DObjPasHelloWorld.dproj.
  2. Press F9 or choose Run > Run.
  3. Press "Run Simulation".

The output displays 60 readings of the coordinates and the angle of a dynamic object over time.

Implementation

Main Form

The MainForm unit implements the following event handler:

  • Button1ClickHandler: Initializes a world, a ground body, and a box object. It creates the box object at coordinates (0, 4), which means that the box object is "in the air". It iterates through 60 steps of the simulation and in each step it passes the coordinates and the angle of the box object to the Log method.

The MainForm unit also implements the following methods:

  • Log: Displays the output of the simulation in the Memo1 control.

Uses

See Also