LibGDX : Scene2D – Box2d – Bumpers Demo

This demo encapsulates some of the Scene2D and Box2D integration I have been playing around with. Specifically collision detection and selection by touch/mouse.

Below is a screenshot with random numbered elements bouncing around inside the view. The walls are supposed to act like pinball bumpers so that when an element hits them they give the element a ‘kick’. The implementation for this is pretty experimental but seems to work well enough for illustration.

Box2D Bumpers

I have implemented a layer which lets you ‘grab’ an element body. When picked up  a selection animation is run around the selected element (the zooming white square). The selection mechanism is actually completely generalised in the sense that it broadcasts events which another layer responds to for the animation. Nice and loosely coupled.

Box2D Bumpers

When an element hits the wall it will bounce and make a clonk sound but when hits another element it will run a flashing animation at the points where the bodies touch and play a boing sound. This illustrates I am detecting what sort of collision is taking place. The layer which has the bouncing elements also has a pool of contact listeners which it can dish out to elements in the view. They are released from the pool when an element is removed (by clicking on it).

Box2D Bumpers

There is some neat stuff here (at least I think so).

These features will hopefully find their way into an actual application  at some point. I have a whole load of bits and pieces which are slowly coalescing into something.

I haven’t created the Android wrapper for this. It’s trivial to put this together and it saves me using my webspace which I am starting to fill at an alarming rate.

Demo code here.

There is a test application bundled as well which uses the LibGDX debug renderer.

This uses LibGDX 0.9.3.

All the code is licensed as Apache 2.0.


9 Responses to “LibGDX : Scene2D – Box2d – Bumpers Demo”

  1. Victor Velasco on May 23rd, 2012 8:11 pm

    Wow, this is great!
    Nice tutorial and thanks for the code sharing!
    Do you think that you can try implement a tiled file (.tmx), tile collision with Box2D for your next tutorial?

    By the way another great tutorial was the Scene transition one


  2. Dranithix Games on July 4th, 2012 12:15 pm

    Yes, I agree with tile collision with tiled maps next if possible.

    And also, with the new Scene2D system in place, are you going to update to it? I have been testing out this library of yours for quite a while.

  3. admin on July 4th, 2012 12:22 pm

    I am waiting for the LibGDX team to finalise their changes to the Scene2D stuff and then I will update all the demos accordingly.

    The tile collision stuff I will have to look into. I’m not sure I have time at the moment though.

  4. Witaly on January 15th, 2013 12:14 pm
  5. admin on January 15th, 2013 3:03 pm

    Oops. Sorry Witaly. I missed that one. Fixed now.

  6. Manish on August 14th, 2014 11:32 am

    Why is it asking for password when i run the apk?

  7. admin on August 14th, 2014 12:53 pm

    I don’t know. I will try it out myself and see what happens.

  8. admin on August 18th, 2014 8:04 pm

    Okay. I have tried this out and I am not seeing this behaviour. It is installing okay but not running properly on my phone although I believe this is an issue separate from your own. Have you – switched on ‘Unknown Sources’ from the security settings on your phone – switched on Android ‘developer options’?

  9. admin on August 18th, 2014 9:33 pm

    I have this all working fine now on my Nexus 4. Please ensure you use the latest versions from github here: