Box2D.Box2DHello
A "Hello World" example for the Box2D third party add-on.
Contents
Location
You can find the SurfSpotFinderApp sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | 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 theButton1ClickHandler
.Memo1
: Displays the output of the application.
How to Use the Sample
- Navigate to one of the locations given above and open FlatBox2DObjPasHelloWorld.dproj.
- Press F9 or choose Run > Run.
- 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 theLog
method.
The MainForm unit also implements the following methods:
Log
: Displays the output of the simulation in theMemo1
control.