Class RectangleHitbox

java.lang.Object
nl.saxion.gameapp.gameobject.hitbox.Hitbox
nl.saxion.gameapp.gameobject.hitbox.RectangleHitbox

public class RectangleHitbox extends Hitbox
Represents an axis-aligned rectangular hitbox defined relative to the size of its parent GameObject.

The position and size of the rectangle are specified as percentages (0.0–1.0) relative to the parent object's width and height. This allows hitboxes to automatically scale when the GameObject is resized.

  • Constructor Details

    • RectangleHitbox

      public RectangleHitbox(GameObject parent, float relOffsetX, float relOffsetY, float relWidth, float relHeight)
      Creates a new rectangle hitbox relative to the parent GameObject.
      Parameters:
      parent - the GameObject this hitbox belongs to
      relOffsetX - x-offset as percentage of parent width
      relOffsetY - y-offset as percentage of parent height
      relWidth - width as percentage of parent width
      relHeight - height as percentage of parent height
  • Method Details

    • getAbsoluteBounds

      public com.badlogic.gdx.math.Rectangle getAbsoluteBounds()
      Returns the rectangle in absolute world coordinates, calculated using the parent GameObject's position and size.
      Returns:
      the rectangle in world coordinates
    • overlaps

      public boolean overlaps(Hitbox other)
      Checks if this hitbox overlaps another hitbox.

      Collision detection automatically handles rectangles, circles, and polygons.

      Specified by:
      overlaps in class Hitbox
      Parameters:
      other - the other hitbox to check collision against
      Returns:
      true if the hitboxes overlap
    • getRelOffsetX

      public float getRelOffsetX()
    • getRelOffsetY

      public float getRelOffsetY()
    • getRelWidth

      public float getRelWidth()
    • getRelHeight

      public float getRelHeight()