EzDevInfo.com

matter-js

a 2D rigid body physics engine for the web

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?  
    }
  }
});

Source: (StackOverflow)

Matter.js Gravity Point

Is it possible to create a single gravity / force point in matter.js that is at the center of x/y coordinates?

I have managed to do it with d3.js but wanted to enquire about matter.js as it has the ability to use multiple polyshapes.

http://bl.ocks.org/mbostock/1021841


Source: (StackOverflow)

Advertisements

How should I place an object using Matter.Object.create in matter.js?

I'm using matter.js and I have vertex data for objects with absolute positions (from SVG files). When I try to place them on the map, they all end up positioned around 0, 0. This is easily observable with this code snippet:

<body>
    <script src="matter-0.8.0.js"></script>

    <script>
     var engine = Matter.Engine.create(document.body);
     var object = Matter.Body.create( 
         { 
             vertices: [ { x: 300, y: 300 }, { x: 200, y: 300 }, { x: 350, y: 200 } ],
             isStatic: true
         });

     Matter.World.add(engine.world, [object]);
     Matter.Engine.run(engine);
    </script>
</body>

Or just look at this jsfiddle: https://jsfiddle.net/vr213z4u/

How is this positioning supposed to work? Do I need to normalize the absolute position data into relative positions and use the position attribute of the options sent to Matter.Object.create? I tried that, but all objects got a little displaced, probably due to my lack of understanding.

Update/clarification: My goal is that the vertices of the created object end up on exactly on the coordinates they have in the source data.


Source: (StackOverflow)