Class MovingPlatform

java.lang.Object
com.codename1.gaming.platformer.MovingPlatform

public final class MovingPlatform extends Object

A platform that travels back and forth along a path of waypoints and carries whatever stands on it.

It is solid from above only, like Tile#ONE_WAY, so an actor can jump up through it. A PlatformWorld moves every platform before it moves the actors, and a Body standing on one is shifted by the platform's step before its own move, so a rider never slides or sinks.

  • Constructor Summary

    Constructors
    Constructor
    Description
    MovingPlatform(int[] path, int width, int height, int speed, int pauseTicks)
    Creates a platform at the first waypoint.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    How far the platform moved horizontally in the last tick.
    int
    How far the platform moved vertically in the last tick.
    int
    Height, fixed point.
    int
    Width, fixed point.
    int
    Left edge, fixed point.
    int
    Top edge, fixed point.
    void
    Advances one tick.

    Methods inherited from class Object

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

    • MovingPlatform

      public MovingPlatform(int[] path, int width, int height, int speed, int pauseTicks)

      Creates a platform at the first waypoint.

      Parameters
      • path: waypoint coordinates of the platform's top-left corner, fixed point, as x0, y0, x1, y1, ...; at least one point
      • width: the width, fixed point
      • height: the height, fixed point
      • speed: distance per tick, fixed point
      • pauseTicks: ticks to wait at each end of the path
  • Method Details

    • step

      public void step()
      Advances one tick.
    • getX

      public int getX()

      Left edge, fixed point.

      Returns

      the x of the top-left corner

    • getY

      public int getY()

      Top edge, fixed point.

      Returns

      the y of the top-left corner

    • getWidth

      public int getWidth()

      Width, fixed point.

      Returns

      the width

    • getHeight

      public int getHeight()

      Height, fixed point.

      Returns

      the height

    • getDx

      public int getDx()

      How far the platform moved horizontally in the last tick.

      Returns

      the x delta, fixed point

    • getDy

      public int getDy()

      How far the platform moved vertically in the last tick.

      Returns

      the y delta, fixed point