Birch-san / liquidfun-play-2

28 stars 3 forks source link

Draw physics bodies individually? #5

Open quinton-ashley opened 1 year ago

quinton-ashley commented 1 year ago

Really incredible work on this! Your project is super underrated. I'm trying to create a new version of p5.play. It uses planck.js behind the scenes but I just found out your version of Box2D is significantly faster. Only problem is that it seems impossible to draw physics bodies individually. In p5.js there's no way to z-index shapes or images, whatever gets drawn just overlaps what was drawn before it. Also users might want to have some effect that only modifies the appearance of one sprite not all of them.

Birch-san commented 1 year ago

ah, because debugDraw doesn't give you any control over ordering? you don't need to use debugDraw.

you can actually just retain in a variable a reference to every body or fixture you create, so that on a timestep you can query their position and draw them in whatever order you prefer.
if you wanna associate bespoke properties with an object, you can do so like so:
https://github.com/Birch-san/box2d-wasm/blob/master/docs/user-data.md

you can iterate over all the bodies and fixtures like this:
https://github.com/Birch-san/box2d-wasm/blob/master/docs/iteration.md
doesn't give you control over order of iteration, but maybe you'll find that useful anyway.

quinton-ashley commented 1 year ago

ooo okay I will look into this soon