Class RectangleHitbox
java.lang.Object
nl.saxion.gameapp.gameobject.hitbox.Hitbox
nl.saxion.gameapp.gameobject.hitbox.RectangleHitbox
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.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionRectangleHitbox(GameObject parent, float relOffsetX, float relOffsetY, float relWidth, float relHeight) Creates a new rectangle hitbox relative to the parent GameObject. -
Method Summary
Modifier and TypeMethodDescriptioncom.badlogic.gdx.math.RectangleReturns the rectangle in absolute world coordinates, calculated using the parent GameObject's position and size.floatfloatfloatfloatbooleanChecks if this hitbox overlaps another hitbox.
-
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 torelOffsetX- x-offset as percentage of parent widthrelOffsetY- y-offset as percentage of parent heightrelWidth- width as percentage of parent widthrelHeight- 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
Checks if this hitbox overlaps another hitbox.Collision detection automatically handles rectangles, circles, and polygons.
-
getRelOffsetX
public float getRelOffsetX() -
getRelOffsetY
public float getRelOffsetY() -
getRelWidth
public float getRelWidth() -
getRelHeight
public float getRelHeight()
-