Supportable Component

Events

LandedOnGround
When entity has landed. This event is triggered with the object the entity landed on.
LiftedOffGround
When entity has lifted off. This event is triggered with the object the entity stood on before lift-off.
CheckLanding
When entity is about to land. This event is triggered with the object the entity is about to land on. Third parties can respond to this event and prevent the entity from being able to land.

Component that detects if the entity collides with the ground. This component is automatically added and managed by the Gravity component. The appropriate events are fired when the entity state changes (lands on ground / lifts off ground). The current ground entity can also be accessed with .ground.

Properties

Methods

Back to top

.canLand

The canLand boolean determines if the entity is allowed to land or not (e.g. perhaps the entity should not land if it's not falling). The Supportable component will trigger a "CheckLanding" event. Interested parties can listen to this event and prevent the entity from landing by setting canLand to false.

Example

var player = Crafty.e("2D, Gravity");
player.bind("CheckLanding", function(ground) {
    if (player.y + player.h > ground.y + player.dy) { // forbid landing, if player's feet are not above ground
        player.canLand = false;
    }
});
Back to top

.ground

Access the ground entity (which may be the actual ground entity if it exists, or null if it doesn't exist) and thus whether this entity is currently on the ground or not. The ground entity is also available through the events, when the ground entity changes.

Back to top

.preventGroundTunneling()

this .preventGroundTunneling([Boolean enable])
enable

Boolean indicating whether to enable continous collision detection or not; if omitted defaults to true

Prevent entity from falling through thin ground entities at high speeds. This setting is disabled by default. This is performed by approximating continous collision detection, which may impact performance negatively. For further details, refer to FAQ#Tunneling.

See Also