Jumper Component

Events

CheckJumping
When entity is about to jump. This event is triggered with the object the entity is about to jump from (if it exists). Third parties can respond to this event and enable the entity to jump.

Make the entity jump in response to key events. Simulates jumping and falling when used with the Gravity component.

Additionally, this component provides the entity with Supportable, Motion and Keyboard methods & events.

Methods

Back to top

.canJump()

The canJump function determines if the entity is allowed to jump or not (e.g. perhaps the entity should be able to double jump). The Jumper component will trigger a "CheckJumping" event. Interested parties can listen to this event and enable the entity to jump by setting canJump to true.

Example

var player = Crafty.e("2D, Jumper");
player.hasDoubleJumpPowerUp = true; // allow player to double jump by granting him a powerup
player.bind("CheckJumping", function(ground) {
    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
});
Back to top

.jump()

public this .jump()

Directly trigger the entity to jump.

Back to top

.jumper()

public this .jumper([Number jumpSpeed,] Array jumpKeys)
jumpSpeed

Vertical jump speed in pixels per second

jumpKeys

Keys to listen for and make entity jump in response

public this .jumper([Number jumpSpeed,] Object jumpInputs)
jumpSpeed

Vertical jump speed in pixels per second

jumpInputs

An object with two properties, keys and mouseButtons.

Constructor to initialize the power of jump and keys to listen to. Component will listen for key events and make the entity jump appropriately.

If second argument is an object, the properties keys and mouseButtons will be used as triggers.

Example

this.jumper(300, ['UP_ARROW', 'W']);
this.jumper(['UP_ARROW', 'W']);

See Also

Back to top

.jumpSpeed()

public this .jumpSpeed(Number jumpSpeed)
jumpSpeed

new vertical jump speed

Change the vertical jump speed.

Example

this.jumpSpeed(300);