liabru / matter-js

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

Can't use gif as body sprite #1062

Closed evanhosni closed 2 years ago

evanhosni commented 3 years ago

I created a body and linked a gif as its sprite:

var body = Bodies.polygon(400, 300, 12, 45, {

    render:{sprite:{

        texture:'./assets/gifs/body.gif',

        xScale: 0.5,

        yScale: 0.5

    }}

});

it is linked correctly, but displays as an image, not an animated gif. Is there a way to get gifs working as sprites?

Thanks!!

liabru commented 2 years ago

Unfortunately animated gifs are not supported by Matter.Render, so you'll need to implement your own approach. You could also look into something like like pixi.js or Phaser which may have support though I'm not certain.

photonstorm commented 2 years ago

Nope, neither Phaser or Pixi support animated gifs as they're not supported by canvas (or webgl). Convert them to spritesheets.

ggorlen commented 2 years ago

If you run Matter.js headlessly, you can use a normal DOM image. See this Stack Overflow answer for an example.