public enum Direction extends java.lang.Enum<Direction>
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).
toFlagValue()| Modifier and Type | Method and 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.
|
Direction |
getOpposite()
Get the opposite value of this direction.
|
float |
toAngle()
Converts this direction to the median angle of the range that is described by this direction.
|
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.
|
static Direction |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.
|
static Direction[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final Direction DOWN
public static final Direction LEFT
public static final Direction RIGHT
public static final Direction UNDEFINED
public static final Direction UP
public static Direction[] values()
for (Direction c : Direction.values()) System.out.println(c);
public static Direction valueOf(java.lang.String name)
name - the name of the enum constant to be returned.java.lang.IllegalArgumentException - if this enum type has no constant with the specified namejava.lang.NullPointerException - if the argument is nullpublic static Direction fromAngle(double angle)
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[
angle - The angle by which the direction will be determined.public static Direction fromFlagValue(byte flagValue)
flagValue - The flag value to convert to a direction.UNDEFINED.public Direction getOpposite()
UP - DOWN LEFT - RIGHT
public float toAngle()
e.g. UP 180
public byte toFlagValue()