craftyjs/Crafty — pull request #708 by mucaho (2014-01-28 23:54:00+00:00)
Title: Gravity Overhaul - Gravity, Twoway, Attach to moving platforms

So I made a **complete overhaul** to how **Gravity & Twoway** work together.
Current state
-----
This is an **initial version**; it is still missing docs, `return this` statements and attaching to moving platforms as described in #601.

Motivation
----
In my opinion, the sharing and modification of 3-4 properties between Twoway and Gravity was **hard to read & maintain** and did not allow for easy **extendability**. Future components that would like to use "forces" just have to `require("Motion")` and apply forces through it's methods.

Changes
----
I introduced a new component called **GroundDetector** which does what Gravity did before: It registers if the entity touches the ground for the first time, if the entity leaves the ground for the first time and enables snapping the entity to the ground. The functionality was split from Gravity so that the to be implemented component **GroundAttacher** (#601) can also listen for these events.

The next component is called **Motion**. Both Gravity and Twoway use that component to add acceleration (gravity constant) or to add force (jump force) in the y direction. "Motion" has a method `getMotionDelta()` which returns the relative change of y that was introduced by all forces. Gravity uses this in order to determine if the entity is falling or rising (jumping).

Issues
----
I'm using `arguments.callee` to unbind an anonymous function; `arguments.callee` is forbidden in [ECMAScript 5](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments/callee#Description). Is that an issue?

Any input would be greatly appreciated! I'm still vague about the component names. Do you have any ideas?