Is there a Physics API? šŸ¤”

Here are more notes about working with matter.js manually…

I figured out how to stop a Physics body from rotating…

It’s… inertia: ā€˜Infinity’ …and it’s case sensitive. If an object is scaled, this setting is lost. So, it has to be reset. Here’s an example…

Matter.Body.scale(red, 1, 1);
Matter.Body.setInertia(red, 'Infinity');

The problem is that scaling is not working as expected. Using ā€œMatter.Body.scaleā€ changes the size of the collision shape, but I’m not able to scale the ā€œSpriteā€ (image) to match the change of that shape. I read the documentation, but I didn’t figure out what was wrong.

Hype is already able to scale both the collision shape and the background image, so I’m missing something…

tomato-physics-test-1.hypetemplate.zip (255.8 KB)

(Pressing a keyboard key will cause the tomato to 64 pixels in diameter.)

However, you can see how Physics freezes if the JavaScript in Test#1 is changed to this…

hypeDocument.setElementProperty(hypeDocument.getElementById('tomato'), 'width', 64, 1, 'linear');
hypeDocument.setElementProperty(hypeDocument.getElementById('tomato'), 'height', 64, 1, 'linear');

So, I think Hype has some pretty creative things going on behind the scenes. I’m not sure, but it seems like Hype is using Matter.js for certain things and Hype’s JavaScript for others.

Also, I tried this… Matter.Body.create(red) …to add a red tomato to the scene. I got the following error…

RangeError: Maximum call stack size exceeded.

This stuff is more complicated than I thought. :thinking:

1 Like