Class EntityPivot
java.lang.Object
de.gurkenlabs.litiengine.entities.EntityPivot
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
ConstructorsConstructorDescriptionEntityPivot(IEntity entity, Align align, Valign valign) Constructs a newEntityPivotwith a specified entity and alignment/vertical alignment, but without specific offsets.EntityPivot(IEntity entity, Align align, Valign valign, double offsetX, double offsetY) Constructs a newEntityPivotwith a specified entity and alignment/vertical alignment.EntityPivot(IEntity entity, EntityPivotType type, double offsetX, double offsetY) Constructs a newEntityPivotwith a specified entity, pivot type, and offsets. -
Method Summary
Modifier and TypeMethodDescriptionGets the associated entity for this pivot.doubleGets the horizontal offset for this pivot.doubleGets the vertical offset for this pivot.getPoint()Calculates and returns the pivot point based on the pivot type and offsets.getType()Gets the type of pivot.voidSets both the horizontal and vertical offsets for this pivot.voidsetOffsetX(double offsetX) Sets the horizontal offset for this pivot.voidsetOffsetY(double offsetY) Sets the vertical offset for this pivot.
-
Constructor Details
-
EntityPivot
Constructs a newEntityPivotwith 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
Constructs a newEntityPivotwith 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
Constructs a newEntityPivotwith 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
Gets the associated entity for this pivot.- Returns:
- The entity associated with this pivot.
-
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
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
Point2Dobject.
-
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
Sets both the horizontal and vertical offsets for this pivot.- Parameters:
offset- APoint2Drepresenting the new offsets.
-