photonstorm/phaser — pull request #254 by cocoademon (2013-12-09 04:52:35+00:00)
Title: Split world update into preUpdate and update.

Physics.preUpdate is called before World.update, which is called before State.update.
Sprite.body.touching is reset in preUpdate, which means sprite subclasses can't test for collisions in their own update methods.

This means the following paradigm currently fails in Phaser:

// in MyGameState.update()
game.physics.collide(group1, group2);

// in MySpriteSubclass.update()
if(this.body.touching.up) {
// do something
// never gets called, as this.body.touching is reset in game.physics.preUpdate
}

This fails because the second call occurs before the first. That is, the sequence of events (for these purposes) boils down to:

1. Physics properties reset (in Body.preUpdate)
2. MySpriteSubclass.update()
3. MyGameState.update() <- which calls collide()

This PR moves the state.update() call to before world.update(), but *after* preUpdate. This makes results of collisions checked in the state available to objects in their own update(), but *also* means physics properties/bounds are properly set before calling any of the collision test methods in ArcadePhysics.