Skip to content
monkstone edited this page Nov 9, 2014 · 16 revisions

Using pbox2d in some more detail

You should have ruby-processing and the pbox2d gem installed, from your processing sketch require pbox2d

require 'pbox2d'

# A list we'll use to track fixed objects
attr_reader :box2d, :boundaries, :boxes

In your before setup you need to include ContactListener (the java interface as a module), by the magic that is jruby this has the effect of implementing the java interface in the Sketch class (that wraps the bare sketch at runtime).

include ContactListener

You then need to create an instance of Box2D in the setup

def setup
  size(400,300)
  @box2d = Box2D.new(self)
  box2d.init_options(gravity: [0, -20])
  box2d.create_world  
  ...

Clone this wiki locally