Description
The Sleeping
property of a PhysicsBody
indicates whether the physics body is currently in a "sleeping" state. Physics bodies automatically enter this state after a period of inactivity to optimize performance. This property can be used to manually wake the body or force it into a sleeping state.
Usage
To check if a physics body is currently sleeping, simply access the Sleeping
property. To wake a sleeping body, set this property to false
. Conversely, to put a body to sleep, set it to true
.
Example
// Example of using the Sleeping property
PhysicsBody myPhysicsBody = new PhysicsBody();
// Check if the body is sleeping
bool isSleeping = myPhysicsBody.Sleeping;
// Wake the body up if it is sleeping
if (isSleeping)
{
myPhysicsBody.Sleeping = false;
}
// Put the body to sleep
myPhysicsBody.Sleeping = true;