Class PhysicsComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.physics.components.PhysicsComponent
Lets an entity be controlled by physics. Do not directly modify the position of a physics-enabled
entity. Instead, use forces to move it.
Entities with a PhysicsComponent will fire "collisionStart" and "collisionEnd" events. See
PhysicsContactListener
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static enum
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreate a physics component with default settings.PhysicsComponent
(PhysicsEngine engine) Create a physics component -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Called when the entity is created and registered.void
dispose()
Called when the component is disposed.void
Entity position needs to be updated to match the new physics position.com.badlogic.gdx.physics.box2d.Body
getBody()
Get the physics body.setBodyType
(com.badlogic.gdx.physics.box2d.BodyDef.BodyType bodyType) Set body typevoid
setEnabled
(boolean enabled) Enable or disable the component.Methods inherited from class com.csse3200.game.components.Component
getEntity, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
PhysicsComponent
public PhysicsComponent()Create a physics component with default settings. -
PhysicsComponent
Create a physics component- Parameters:
engine
- The physics engine to attach the component to
-
-
Method Details
-
setBodyType
Set body type- Parameters:
bodyType
- body type, default = dynamic- Returns:
- self
-
getBody
public com.badlogic.gdx.physics.box2d.Body getBody()Get the physics body.- Returns:
- physics body if entity has been created, null otherwise.
-
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. -
earlyUpdate
public void earlyUpdate()Entity position needs to be updated to match the new physics position. This should happen before other updates, which may use the new position.- Overrides:
earlyUpdate
in classComponent
-
dispose
public void dispose()Description copied from class:Component
Called when the component is disposed. Dispose of any internal resources here. -
setEnabled
public void setEnabled(boolean enabled) Description copied from class:Component
Enable or disable the component. While disabled, a component does not run update() or earlyUpdate(). Other events inside the component may still fire. The component can still be disposed while disabled.- Overrides:
setEnabled
in classComponent
- Parameters:
enabled
- Should component be enabled
-