liabru / matter-js

a 2D rigid body physics engine for the web ▲● ■
MIT License
16.57k stars 1.96k forks source link

Clipping textures of a body? #416

Closed voydz closed 6 years ago

voydz commented 7 years ago

Hey,

I am playing around with matter. Recently I faced the problem, that I need to clip a given textures to the bounds of the body.

Anybody got an idea how to tackle this? I searched the docs, but I can't find an option for this.

Thanks in advance.

liabru commented 7 years ago

There's nothing for this in the built in renderer unfortunately. I suggest you fork it and add the feature, see rendering. There's an example on codepen that does something similar, check it out.

voydz commented 7 years ago

Hi @liabru, thanks for the information.

I got myself a working implementation. For now its way to specific and dirty to contribute back to matter-js.

For anyone who is curious, or wants to implement this in matter-js, I made a gist containing my current renderer code here. This is basically a quick an dirty extend/override of matter's default renderer.

P.S.: I know it does not belong here @liabru, but I would be very glad if you could take a look at https://github.com/liabru/matter-attractors/issues/1 (PR is included).