Simple Examples?

Hi,

First post, so please be nice! 😀

I'm wondering if anyone has any simple examples ( a stack of blocks, anything!! ) of how to use the JBox2D 2.0 code.

I see there are demos available, but I just can't figure out how to create my own project from scratch, as they all extend the AbstractExample class, and are all run using the Testbed class. I understand the code, and I've used version 1.4.1. before to create a simple program (albeit extending the PTest class that was provided!)

I'm being incredibly stupid here, I know, but I've been trying to get this to work for almost 2 weeks now, and I'm struggling to even make a start.

The aim is to have the JBox2D Applet as part of a GUI, with controls on the side, so if anyone has any pointers on embedding it in a GUI, that would be great too.

I SERIOUSLY appreciate any help ANYONE can give me with this.

Thank you. 🙂
Sorry, I don't have any applet examples. Really all you need to do is find an example out there using a fixed frame rate loop (lots of examples out there).

Something like this (just cut and pasted out of my base game app):
Code:
   float desiredTPF = 1000 / 30; // which is 1000 ms (1 sec) divided by the desired FPS, 30.
   long lastFrame = System.currentTimeMillis();
   float yield = 10000f;
   float averageTPF = desiredTPF;
   float lastTPF;
   long timeNow;

   while (!done) {
      update();
      render(g);

      // Timing code.
      timeNow = System.currentTimeMillis();
      lastTPF = timeNow - lastFrame;
      // Rolling average for the last 10 frames.
      averageTPF = (averageTPF * 10 + lastTPF) / 11;
      lastFrame = timeNow;
      yield += yield * ((desiredTPF / averageTPF) - 1) * 0.1f + 0.05f;
      for (int j = 0; j < yield; j++) Thread.yield();
   }

Note: TPF = Time per frame, FPS = frames per second. Also, this is a pretty primitive loop as i don't try to separate the update from rendering.

In the update(), you'll want to have a call to world.step with the first parameter being 1/desiredFPS or just hard code it to 1/60 like the JBox2D AbstractExample does. ex.
Code:
m_world.step(1/desiredFPS, 10);


Then in the render() method, draw you bodies/shapes based on their current location. And that's pretty much it.
Thanks for your reply.

I don't suppose you could point me in the direction of such an example?

All I really need to get started is to know how to create even a single block on a piece of ground, like in the original JBox2D demos.

I just can't seem to get my head round creating even a simple thing like that and it's really starting to stress me out!!

Any help is seriously(!!!) appreciated... 🙂
Just an update.

I managed to get the GUI part working, albeit with my program using the OLD JBox2D code.

See here if you wish to do a similar thing, it's very useful: http://processing.org/hacks/hacks:swingsliders

I'd still really appreciate any help with JBox2D 2.0, I'd like to transfer my system across to the new version, if possible 🙂

Original thread: https://box2d.org/forum/viewtopic.php?t=4420