Matter-js: What does Sleeping do?

Created on 21 Jan 2017  路  2Comments  路  Source: liabru/matter-js

I'm trying to optimize my game. I came across sleeping: http://brm.io/matter-js/docs/classes/Sleeping.html and was wondering exactly what it was for. I have an agario style game. Will this help with optimization? Should I put it in? Any suggestions on how to implement it? Also, how frequently should the sleeping state be set, every frame?

question

Most helpful comment

See the sleeping demo and source. What this does is it tells the engine to stop updating and collision checking bodies that have come to rest.

This is a big performance boost if you have a lot of bodies in collision at rest (e.g. a stack of boxes). Sleeping bodies are woken up when a non-sleeping body collides with them. The downside is that the result not always exactly the same as if they were not sleeping, but it's usually good enough.

All you need to do is set engine.enableSleeping = true once when you create your engine. It will automatically handle the rest.

All 2 comments

See the sleeping demo and source. What this does is it tells the engine to stop updating and collision checking bodies that have come to rest.

This is a big performance boost if you have a lot of bodies in collision at rest (e.g. a stack of boxes). Sleeping bodies are woken up when a non-sleeping body collides with them. The downside is that the result not always exactly the same as if they were not sleeping, but it's usually good enough.

All you need to do is set engine.enableSleeping = true once when you create your engine. It will automatically handle the rest.

Thank you liabru! I was doing it it in every frame in update before!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

liabru picture liabru  路  3Comments

maximilianberndt picture maximilianberndt  路  4Comments

Zhaopengyang picture Zhaopengyang  路  3Comments

TimuJiang picture TimuJiang  路  4Comments

christianmalek picture christianmalek  路  4Comments