Friday 19 July 2013

Getting started with JBox2D

The first step on the road to realising my Pinball machine project is learning how to use JBox2D. As a back-end Java programmer, by profession, I chose to start learning this over JavaFX for a few reasons:

  1. The skill set required for JBox2D is more closely aligned to mine than that required for JavaFX - so the learning curve should be less steep. 
  2. The JBox2D team have done a fantastic job of creating a testing framework for easily prototyping and visualising ideas. 
  3. Learning how to make the physics engine model complex behaviour should be a lot of fun. 

With the wealth of example tests, documentation and a great toolset, I anticipated being up and running in no time.

Stumbling at the first hurdle 

I had expected there to be growing pains as I started to learn JBox2D, since I've never used a physics engine before and it is an involved subject, but you have a crisis of confidence when you stumble whilst trying to get up and running.

How to build the code

The QuickStart guide lays out 3 easy steps for getting started - checkout the code, import it as a Maven project in to an IDE and finally run the TestbedMain class to start the Testbed suite.

Unfortunately, when I followed the instructions, I encountered compilation errors which prevented the Testbed from running. Whilst I was able to find a work around, I've subsequently identified where I went wrong - and what isn't completely in the QuickStart guide.

Where step 2 says "Import to your IDE as a Maven project (using the pom.xml descriptor in the root folder)", I interpreted this as the parent pom.xml file in the jbox2d-read-only, root folder. but I've found that if instead you only import the module jbox2d-read-only\jbox2d-testbed using the pom.xml file from found within this directory that the Testbed suite launches - without having to mess around with deleting files or changing their package headers.

Note: You may, however, have to run mvn clean install on the jbox2d-read-only\jbox2d-library module in order to make the necessary JBox2D library dependency available to the Testbed module. 


Once everything is configured properly, the Testbed Swing GUI should launch and you can start experimenting with all of the pre-written, example tests.


Then it's on to writing our own tests and plugging them in to the Testbed!





Prev (Leaping in to action)               Next (Adding tests to a JBox2D Testbed)

No comments:

Post a Comment