Class JumpAbility

java.lang.Object
com.codename1.gaming.platformer.Ability
com.codename1.gaming.platformer.JumpAbility

public class JumpAbility extends Ability

Jumping, with the forgiveness that makes a platformer feel right:

  • Coyote time: a jump still works for coyoteTicks after walking off a ledge.
  • Jump buffering: a press up to bufferTicks before landing jumps on landing.
  • Variable height: releasing the button while rising cuts the jump.
  • Multi-jump: maxJumps above 1 allows double (or more) jumps in the air.
  • Drop through: down + jump on a one-way platform falls through it instead.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    Upward speed of an air jump.
    int
    Ticks a press is remembered before landing.
    int
    Ticks after leaving the ground that a jump is still a ground jump.
    int
    Upward speed at take-off, fixed point per tick.
    int
    Jumps allowed before landing again; 2 is a double jump.
    int
    Fraction of upward speed kept when the button is released early.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Runs before any ability sets velocity: timers and input edges.
    long
    hashState(long h)
    Mixes the ability's own state into a hash, so two runs that diverge inside an ability are caught.
    void
    Runs after the body moved, with the new contacts.
    void
    Sets velocity and claims a MovementState.
    void
    Forgets what the ability was in the middle of, when its actor respawns: a dash, a buffered jump or a grip does not outlive a death.
    void
    resetJumps(int used)
    Lets the actor jump again in the air, as a wall jump or a bounce does.

    Methods inherited from class Ability

    isEnabled, mix, setEnabled

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • jumpSpeed

      public int jumpSpeed
      Upward speed at take-off, fixed point per tick.
    • airJumpSpeed

      public int airJumpSpeed
      Upward speed of an air jump.
    • maxJumps

      public int maxJumps
      Jumps allowed before landing again; 2 is a double jump.
    • coyoteTicks

      public int coyoteTicks
      Ticks after leaving the ground that a jump is still a ground jump.
    • bufferTicks

      public int bufferTicks
      Ticks a press is remembered before landing.
    • releaseCut

      public int releaseCut
      Fraction of upward speed kept when the button is released early.
  • Constructor Details

    • JumpAbility

      public JumpAbility()
  • Method Details

    • earlyProcess

      public void earlyProcess(Actor c, PlatformWorld world)
      Description copied from class: Ability

      Runs before any ability sets velocity: timers and input edges.

      Parameters
      • c: the actor
      • world: the world
      Overrides:
      earlyProcess in class Ability
    • process

      public void process(Actor c, PlatformWorld world)
      Description copied from class: Ability

      Sets velocity and claims a MovementState.

      Parameters
      • c: the actor
      • world: the world
      Specified by:
      process in class Ability
    • lateProcess

      public void lateProcess(Actor c, PlatformWorld world)
      Description copied from class: Ability

      Runs after the body moved, with the new contacts.

      Parameters
      • c: the actor
      • world: the world
      Overrides:
      lateProcess in class Ability
    • resetJumps

      public void resetJumps(int used)

      Lets the actor jump again in the air, as a wall jump or a bounce does.

      Parameters
      • used: jumps to count as used afterwards
    • hashState

      public long hashState(long h)
      Description copied from class: Ability

      Mixes the ability's own state into a hash, so two runs that diverge inside an ability are caught. The default mixes nothing.

      Parameters
      • h: the running hash
      Returns

      the updated hash

      Overrides:
      hashState in class Ability
    • reset

      public void reset()
      Description copied from class: Ability
      Forgets what the ability was in the middle of, when its actor respawns: a dash, a buffered jump or a grip does not outlive a death. The default does nothing; an ability with per-run state overrides it.
      Overrides:
      reset in class Ability