Enum Class Direction

java.lang.Object
java.lang.Enum<Direction>
de.gurkenlabs.litiengine.Direction
All Implemented Interfaces:
Serializable, Comparable<Direction>, Constable

public enum Direction extends Enum<Direction>
This enum defines the four dimensional directions in 2D space.

It can provide a simplified way to look at a rotation or angle which is particularly useful in tile based games.

Directions can be converted to or constructed from angles (specified in degrees).
The directions also specify a flag that can be used to exchange the information in an size-optimized manner (e.g. for network communication).

See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    Direction pointing down with a flag value of 1 and an angle of 360 degrees.
    Direction pointing left with a flag value of 2 and an angle of 270 degrees.
    Direction pointing right with a flag value of 4 and an angle of 90 degrees.
    Undefined direction with a flag value of 8 and an angle of 0 degrees.
    Direction pointing up with a flag value of 16 and an angle of 180 degrees.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Direction
    fromAngle(double angle)
    Gets a direction corresponding to the specified angle.
    static Direction
    fromFlagValue(byte flagValue)
    Get a value of this enumeration that corresponds to the specified flagValue.
    Get the opposite value of this direction.
    float
    Converts this direction to the median angle of the range that is described by this direction.
    byte
    Gets a flag value that can be used to exchange the information of this enum value in an size-optimized manner (e.g.
    static Direction
    Returns the enum constant of this class with the specified name.
    static Direction[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • DOWN

      public static final Direction DOWN
      Direction pointing down with a flag value of 1 and an angle of 360 degrees.
    • LEFT

      public static final Direction LEFT
      Direction pointing left with a flag value of 2 and an angle of 270 degrees.
    • UNDEFINED

      public static final Direction UNDEFINED
      Undefined direction with a flag value of 8 and an angle of 0 degrees.
    • UP

      public static final Direction UP
      Direction pointing up with a flag value of 16 and an angle of 180 degrees.
  • Method Details

    • values

      public static Direction[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Direction valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • fromAngle

      public static Direction fromAngle(double angle)
      Gets a direction corresponding to the specified angle. Every direction translates to 1/4th (90°) of a full circle.
           o 180 o        DOWN = [0-45[ & [315-360]
         o         o
        o           o     RIGHT = [45-135[
       270          90
        o           o     UP = [135-225[
         o         o
           o  0  o        LEFT = [225-315[
       
      Parameters:
      angle - The angle by which the direction will be determined.
      Returns:
      The direction that corresponds to the specified angle.
    • fromFlagValue

      public static Direction fromFlagValue(byte flagValue)
      Get a value of this enumeration that corresponds to the specified flagValue.
      Parameters:
      flagValue - The flag value to convert to a direction.
      Returns:
      A direction that corresponds to the specified flag value or UNDEFINED.
    • getOpposite

      public Direction getOpposite()
      Get the opposite value of this direction.
       UP - DOWN
       LEFT - RIGHT
       
      Returns:
      The opposite direction.
    • toAngle

      public float toAngle()
      Converts this direction to the median angle of the range that is described by this direction.
       e.g. UP 180
       
      Returns:
      The mean angle of this direction.
    • toFlagValue

      public byte toFlagValue()
      Gets a flag value that can be used to exchange the information of this enum value in an size-optimized manner (e.g. for network communication).
      Returns:
      The immutable flag value that is assigned to this direction.