Gravity
Adds gravitational pull to the entity.
Back to top
.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 not specified, 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")
Back to top
.gravityConst
public this .gravityConst(g)
- g
- gravitational constant
Set the gravitational constant to g. The default is .2. The greater g, the faster the object falls.
Example
Crafty.e("2D, DOM, Color, Gravity")
.color("red")
.attr({ w: 100, h: 100 })
.gravity("platform")
.gravityConst(2)
Back to top
.antigravity
public this .antigravity()
Disable gravity for this component. It can be reenabled by calling .gravity()

@craftyjs
#crafty@freenode.net
google groups
louis@craftyjs.com
github