Box2d for python mode

edited December 2017 in Python Mode

I'm using python mode and try to use box2d_processing library, but Vec2 is not working. Is there someone who knows how to use that?


  • Could you please post a small but complete example that doesn't work as you'd expect it to?

  • 2DK2DK
    edited December 2017

    Hi JonathanFeinberg, it's an honor to talk to you, and thank you for making python mode! I'm using Processing 3.3.6 with python mode of 3035, and the code below returns error that is, 'Vec2' is not defined.


    def setup():
        size(500, 400)
        box2d = Box2DProcessing(this)
        center = Vec2(width / 2, height / 2)
  • edited December 2017 Answer ✓

    • Seems like add_library() can only import the library whose ".jar" filename matches its string argument.
    • However, libraries such as "fisica", "box2d_processing" & "LiquidFunProcessing" have an extra ".jar" file there too.
    • And that additional ".jar" file is the library "jbox2d".
    • Which btW, got the class Vec2 which you are struggling to use in your sketch.
    • Unless we can pass the whole path to add_library(), Python Mode can't reach that helper library.
    • But don't fret! I've found out a workaround for it:
    • Manually make "jbox2d" globally available as a 3rd-party library on its own.
    1. Just go to the sketch's subfolder "libraries/" where all 3rd-party libraries are installed.
    2. Create a folder there named "jbox2d". And inside that, another folder called "library".
    3. Pick n1 of those "jbox2d.jar" files from "fisica", "box2d_processing" or "LiquidFunProcessing", and copy it into your new "jbox2d/library/" folder.
    4. Rename that ".jar" file exactly as "jbox2d.jar". So it matches its parent folder "jbox2d".
    5. Now you can finally import it into your sketch like this: add_library('jbox2d').
    def setup():
        size(500, 400)
        global box2d, center
        box2d = Box2DProcessing(this)
        center = Vec2(width>>1, height>>1)
        print center
Sign In or Register to comment.