Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matter.js Sprite Size

I am making a physics simulation using matter.js.

My question is, is it possible to change the sprite size? Or is that not possible using only matter.js?

This is what I have so far:

Bodies.circle(x, y, 46, {
  render: {
    sprite: {
      texture: 'images/stone.png'
      //Is there a 'width:' or 'height' property?  
    }
  }
});
like image 884
Brad Thiessen Avatar asked Jun 06 '15 02:06

Brad Thiessen


People also ask

What is matter JS physics in phaser?

Matter.js is another supported physics engine in Phaser 3.x and while it offers quite a bit of functionality that arcade physics doesn’t offer, it also offers custom polygon physics bodies. In this tutorial, we’re going to explore collisions once more in a Phaser game, but this time with Matter.js and more refined boundaries.

Is the physics body of a sprite pixel perfect?

In the above example, we have two sprites, one of which is animated. Both sprites have a custom physics body which is fitted to the image. While this isn’t pixel perfect due to using polygons, it is a lot more refined than what we saw in the previous tutorial.

What is the physics body in the sprites?

Both sprites have a custom physics body which is fitted to the image. While this isn’t pixel perfect due to using polygons, it is a lot more refined than what we saw in the previous tutorial. The physics body is only visible for demonstration purposes and can be hidden in a realistic scenario.

How do I move an obstacle with a plane sprite?

For clarity, the plane sprite is using plane1.png and not null because plane1.png is the first frame in the animation while the obstacle is not animated. To move the obstacle, change the updateScene to look like the following: If we did nothing else and ran our game, the obstacle would move until it collides with the plane.


1 Answers

Try this:

Bodies.circle(x, y, 46, {
  render: {
    sprite: {
      texture: 'images/stone.png',
      xScale: 2,
      yScale: 2
    }
  }
});

Also see here in the docs.

like image 81
liabru Avatar answered Oct 09 '22 05:10

liabru