How do I import and attach a PNG or GIF to a shape in Box2dWeb?
The best resource I could find online is at: http://www.jeremyhubble.com/box2d.html
However, this “tutorial” doesn’t give much explanation about how images are actually used. So it is clearly possible, but I can’t get the userData trick to work.
I’ve answered this for you over on gamedev now (along with an example), but here’s the bottom line:
You are generally responsible for rendering the state of your box2d world – the “userData trick” you refer to is not really to do with the box2d framework.
userData is a placeholder for arbitrary data that you want to associate to a body. This could be anything – a string, function, object, etc. This data is typically used to help you render your world during the update loop, which is exactly what the resource you linked to does – If you look at the processObjects function it uses the imgsrc value to create an Image object and draws it onto the canvas at the correct location. (This isn’t really a good idea because the image is created once per object per iteration – I would suggest it should only be created once)