/image-to-box2d-body

proof-of-concept game build pipeline for converting an image to a Box2D body

Primary LanguageJavaScript

How to convert drawn images into Box2D objects

This question nerd-sniped me hard, so I went on a magical journey to figure out how to turn a drawn raster image into Box2D objects.

sword and wand → this pipeline → box2d sword and wand

This proof of concept expects to find an input file input.png in this project root directory. Then run make.

You should find a bunch of intermediate formats in out/ and if you open game.html, you should see a Box2D debug view with your objects loaded.

See the makefile for how the build steps work.

Dependencies:

  • make

  • Node.js and npm

    Run npm install in the project root directory to download Node.js dependencies to the local node_modules directory.

  • Inkscape

  • potrace

  • ImageMagick (convert and mogrify)

License

CC0 license

To the extent possible under law, I waive all copyright and related or neighbouring rights to this work.