Class PhysicsComponent
java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.physics.components.PhysicsComponent
public class PhysicsComponent extends Component
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
Nested Classes Modifier and Type Class Description static classPhysicsComponent.AlignXstatic classPhysicsComponent.AlignY - 
Field Summary
 - 
Constructor Summary
Constructors Constructor Description PhysicsComponent()Create a physics component with default settings.PhysicsComponent(PhysicsEngine engine)Create a physics component - 
Method Summary
Modifier and Type Method Description voidcreate()Called when the entity is created and registered.voiddispose()Called when the component is disposed.voidearlyUpdate()Entity position needs to be updated to match the new physics position.BodygetBody()Get the physics body.PhysicsComponentsetBodyType(BodyDef.BodyType bodyType)Set body typevoidsetEnabled(boolean enabled)Enable or disable the component.Methods inherited from class com.deco2800.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
Get the physics body.- Returns:
 - physics body if entity has been created, null otherwise.
 
 - 
create
public void create()Description copied from class:ComponentCalled 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:
 earlyUpdatein classComponent
 - 
dispose
public void dispose()Description copied from class:ComponentCalled when the component is disposed. Dispose of any internal resources here. - 
setEnabled
public void setEnabled(boolean enabled)Description copied from class:ComponentEnable 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:
 setEnabledin classComponent- Parameters:
 enabled- Should component be enabled
 
 -