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?
}
}
});
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.
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.
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.
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.
Try this:
Bodies.circle(x, y, 46, {
render: {
sprite: {
texture: 'images/stone.png',
xScale: 2,
yScale: 2
}
}
});
Also see here in the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With