Class ColliderComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.physics.components.ColliderComponent
- Direct Known Subclasses:
HitboxComponent
Attaches a physics collider to an entity. By default, this is a rectangle the same size as the
entity's scale. This allows an entity to collide with other physics objects, or detect collisions
without interaction (if sensor = true)
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Called when the entity is created and registered.void
dispose()
Called when the component is disposed.com.badlogic.gdx.physics.box2d.Fixture
short
getLayer()
setAsBox
(com.badlogic.gdx.math.Vector2 size) Set physics as a box with a given size.setAsBox
(com.badlogic.gdx.math.Vector2 size, com.badlogic.gdx.math.Vector2 position) Set physics as a box with a given size and local position.setAsBoxAligned
(com.badlogic.gdx.math.Vector2 size, PhysicsComponent.AlignX alignX, PhysicsComponent.AlignY alignY) Set physics as a box with a given size.setDensity
(float density) Set densitysetFriction
(float friction) Set friction.setLayer
(short layerMask) Set the collider layer, used in collision logicsetRestitution
(float restitution) Set restitutionsetSensor
(boolean isSensor) Set whether this physics component is a sensor.setShape
(com.badlogic.gdx.physics.box2d.Shape shape) Set shapeMethods inherited from class com.csse3200.game.components.Component
earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
ColliderComponent
public ColliderComponent()
-
-
Method Details
-
create
public void create()Description copied from class:Component
Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished. -
setAsBox
Set physics as a box with a given size. Box is centered around the entity.- Parameters:
size
- size of the box- Returns:
- self
-
setAsBoxAligned
public ColliderComponent setAsBoxAligned(com.badlogic.gdx.math.Vector2 size, PhysicsComponent.AlignX alignX, PhysicsComponent.AlignY alignY) Set physics as a box with a given size. Box is aligned based on alignment.- Parameters:
size
- size of the boxalignX
- how to align x relative to entityalignY
- how to align y relative to entity- Returns:
- self
-
setAsBox
public ColliderComponent setAsBox(com.badlogic.gdx.math.Vector2 size, com.badlogic.gdx.math.Vector2 position) Set physics as a box with a given size and local position. Box is centered around the position.- Parameters:
size
- size of the boxposition
- position of the box center relative to the entity.- Returns:
- self
-
setFriction
Set friction. This affects the object when touching other objects, but does not affect friction with the ground.- Parameters:
friction
- friction, default = 0- Returns:
- self
-
setSensor
Set whether this physics component is a sensor. Sensors don't collide with other objects but still trigger collision events. See: https://www.iforce2d.net/b2dtut/sensors- Parameters:
isSensor
- true if sensor, false if not. default = false.- Returns:
- self
-
setDensity
Set density- Parameters:
density
- Density and size of the physics component determine the object's mass. default = 0- Returns:
- self
-
setRestitution
Set restitution- Parameters:
restitution
- restitution is the 'bounciness' of an object, default = 0- Returns:
- self
-
setShape
Set shape- Parameters:
shape
- shape, default = bounding box the same size as the entity- Returns:
- self
-
getFixture
public com.badlogic.gdx.physics.box2d.Fixture getFixture()- Returns:
- Physics fixture of this collider. Null before created()
-
setLayer
Set the collider layer, used in collision logic- Parameters:
layerMask
- Bitmask ofPhysicsLayer
this collider belongs to- Returns:
- self
-
getLayer
public short getLayer()- Returns:
- The
PhysicsLayer
this collider belongs to
-
dispose
public void dispose()Description copied from class:Component
Called when the component is disposed. Dispose of any internal resources here.
-