From 5793f0784e14531ac03ec4ed1a3a3e3237912cba Mon Sep 17 00:00:00 2001 From: mucaho Date: Sat, 21 Mar 2015 14:34:59 +0100 Subject: [PATCH] Improve docs Improve docs of Supportable and Twoway with examples of realistic, custom land and jump behavior. --- src/controls/controls.js | 12 ++++++++---- src/spatial/2d.js | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/controls/controls.js b/src/controls/controls.js index 72b5d4abd..0632b9882 100644 --- a/src/controls/controls.js +++ b/src/controls/controls.js @@ -1300,11 +1300,15 @@ Crafty.c("Twoway", { * @example * ~~~ * var player = Crafty.e("2D, Twoway"); + * player.hasDoubleJumpPowerUp = true; // allow player to double jump by granting him a powerup * player.bind("CheckJumping", function(ground) { - * if (!ground && player.hasDoubleJumpPowerUp) { // custom behaviour - * player.hasDoubleJumpPowerUp = false; - * player.canJump = true; - * } + * if (!ground && player.hasDoubleJumpPowerUp) { // allow player to double jump by using up his double jump powerup + * player.canJump = true; + * player.hasDoubleJumpPowerUp = false; + * } + * }); + * player.bind("LandedOnGround", function(ground) { + * player.hasDoubleJumpPowerUp = true; // give player new double jump powerup upon landing * }); * ~~~ */ diff --git a/src/spatial/2d.js b/src/spatial/2d.js index 9b5ceaaa0..5e42dfc10 100644 --- a/src/spatial/2d.js +++ b/src/spatial/2d.js @@ -951,8 +951,9 @@ Crafty.c("Supportable", { * ~~~ * var player = Crafty.e("2D, Gravity"); * player.bind("CheckLanding", function(ground) { - * if (player.isAirplane) // custom behaviour + * if (player.y + player.h > ground.y + player.vy) { // forbid landing, if player's feet are not above ground * player.canLand = false; + * } * }); * ~~~ */