Gravity Component
Adds gravitational pull to the entity.
Additionally, this component provides the entity with Supportable
and Motion
methods & events.
Simulates jumping and falling when used with the Twoway
component and is thus well suited for side-scrolling platformer type games.
This component should not be used alongside Fourway
or Multiway
.
See Also
Methods
.antigravity()
public this .antigravity()
Disable gravity for this component. It can be reenabled by calling .gravity()
.gravity()
public this .gravity([comp])
- comp
The name of a component that will stop this entity from falling
Enable gravity for this entity no matter whether comp parameter is specified or not. If comp parameter is specified all entities with that component will stop this entity from falling. For a player entity in a platform game this would be a component that is added to all entities that the player should be able to walk on.
Example
Crafty.e("2D, DOM, Color, Gravity")
.color("red")
.attr({ w: 100, h: 100 })
.gravity("platform");
.gravityConst()
public this .gravityConst(g)
- g
gravitational constant in pixels per second squared
Set the gravitational constant to g for this entity. The default is 500. The greater g, the stronger the downwards acceleration.
Example
Crafty.e("2D, DOM, Color, Gravity")
.color("red")
.attr({ w: 100, h: 100 })
.gravityConst(750)
.gravity("platform");