Class EntityPivot

java.lang.Object
de.gurkenlabs.litiengine.entities.EntityPivot

public class EntityPivot extends Object
The EntityPivot class represents a pivot point for an entity, which can be used to determine the entity's position relative to a specific alignment or offset. This is particularly useful for positioning entities in the game world with precision.
  • Constructor Summary

    Constructors
    Constructor
    Description
    EntityPivot(IEntity entity, Align align, Valign valign)
    Constructs a new EntityPivot with a specified entity and alignment/vertical alignment, but without specific offsets.
    EntityPivot(IEntity entity, Align align, Valign valign, double offsetX, double offsetY)
    Constructs a new EntityPivot with a specified entity and alignment/vertical alignment.
    EntityPivot(IEntity entity, EntityPivotType type, double offsetX, double offsetY)
    Constructs a new EntityPivot with a specified entity, pivot type, and offsets.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the associated entity for this pivot.
    double
    Gets the horizontal offset for this pivot.
    double
    Gets the vertical offset for this pivot.
    Calculates and returns the pivot point based on the pivot type and offsets.
    Gets the type of pivot.
    void
    Sets both the horizontal and vertical offsets for this pivot.
    void
    setOffsetX(double offsetX)
    Sets the horizontal offset for this pivot.
    void
    setOffsetY(double offsetY)
    Sets the vertical offset for this pivot.

    Methods inherited from class java.lang.Object

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

    • EntityPivot

      public EntityPivot(IEntity entity, EntityPivotType type, double offsetX, double offsetY)
      Constructs a new EntityPivot with a specified entity, pivot type, and offsets. This constructor allows for the creation of a pivot based on a predefined pivot type, which can include the center of the entity's collision box or an offset from its current position.
      Parameters:
      entity - The entity to which this pivot is associated.
      type - The type of pivot, determining how the pivot point is calculated.
      offsetX - The horizontal offset from the calculated pivot point.
      offsetY - The vertical offset from the calculated pivot point.
      Throws:
      IllegalArgumentException - If the pivot type is COLLISIONBOX_CENTER but the entity is not a collision entity.
    • EntityPivot

      public EntityPivot(IEntity entity, Align align, Valign valign)
      Constructs a new EntityPivot with a specified entity and alignment/vertical alignment, but without specific offsets. This constructor is a convenience method that defaults the offsets to 0, effectively placing the pivot point directly at the specified alignment within the entity. It delegates to the primary constructor with offset parameters set to 0.
      Parameters:
      entity - The entity to which this pivot is associated.
      align - The horizontal alignment for the pivot, determining its horizontal position relative to the entity.
      valign - The vertical alignment for the pivot, determining its vertical position relative to the entity.
    • EntityPivot

      public EntityPivot(IEntity entity, Align align, Valign valign, double offsetX, double offsetY)
      Constructs a new EntityPivot with a specified entity and alignment/vertical alignment. This constructor is a convenience method that allows for the creation of a pivot based on alignment parameters, which are then converted into offset values.
      Parameters:
      entity - The entity to which this pivot is associated.
      align - The horizontal alignment for the pivot.
      valign - The vertical alignment for the pivot.
  • Method Details

    • getEntity

      public IEntity getEntity()
      Gets the associated entity for this pivot.
      Returns:
      The entity associated with this pivot.
    • getType

      public EntityPivotType getType()
      Gets the type of pivot.
      Returns:
      The pivot type.
    • getOffsetX

      public double getOffsetX()
      Gets the horizontal offset for this pivot.
      Returns:
      The horizontal offset.
    • getOffsetY

      public double getOffsetY()
      Gets the vertical offset for this pivot.
      Returns:
      The vertical offset.
    • getPoint

      public Point2D getPoint()
      Calculates and returns the pivot point based on the pivot type and offsets. This method determines the exact location of the pivot point, taking into account the entity's current position, size, and the specified offsets.
      Returns:
      The calculated pivot point as a Point2D object.
    • setOffsetX

      public void setOffsetX(double offsetX)
      Sets the horizontal offset for this pivot.
      Parameters:
      offsetX - The new horizontal offset.
    • setOffsetY

      public void setOffsetY(double offsetY)
      Sets the vertical offset for this pivot.
      Parameters:
      offsetY - The new vertical offset.
    • setOffset

      public void setOffset(Point2D offset)
      Sets both the horizontal and vertical offsets for this pivot.
      Parameters:
      offset - A Point2D representing the new offsets.