Package com.deco2800.game.components
Class Component
java.lang.Object
com.deco2800.game.components.Component
- Direct Known Subclasses:
AchievementsStatsComponent
,AITaskComponent
,BackgroundSoundComponent
,CameraComponent
,ColliderComponent
,CombatStatsComponent
,DeBuff
,EnemyAnimationController
,GoldComponent
,InputComponent
,InventoryComponent
,ItemBar
,ItemComponent
,MainGameActions
,MainMenuActions
,newItembar
,ObstacleEventHandler
,PhysicsComponent
,PhysicsMovementComponent
,PlayerActions
,PlayerAnimationController
,RenderComponent
,SoundComponent
,SpaceshipAttackController
,Terminal
,TouchAttackComponent
public class Component
extends java.lang.Object
Core component class from which all components inherit. Contains logic for creating, updating,
and disposing. Components can be attached to an entity to give it specific behaviour. It is
unlikely that changes will need to be made here.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description Component()
-
Method Summary
Modifier and Type Method Description void
create()
Called when the entity is created and registered.void
dispose()
Called when the component is disposed.void
earlyUpdate()
Early update called once per frame of the game, before update().Entity
getEntity()
Get the entity to which this component belongs.void
setEnabled(boolean enabled)
Enable or disable the component.void
setEntity(Entity entity)
Set the entity to which this component belongs.java.lang.String
toString()
void
triggerEarlyUpdate()
Used to trigger the component to early-update itself.void
triggerUpdate()
Used to trigger the component to update itself.void
update()
Called once per frame of the game, and should be used for most component logic.
-
Field Details
-
Constructor Details
-
Component
public Component()
-
-
Method Details
-
create
public void create()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()Early update called once per frame of the game, before update(). Use this only for logic that must run before other updates, such as physics. Not called if component is disabled. -
update
public void update()Called once per frame of the game, and should be used for most component logic. Not called if component is disabled. -
dispose
public void dispose()Called when the component is disposed. Dispose of any internal resources here. -
setEntity
Set the entity to which this component belongs. This is called by the Entity, and should not be set manually.- Parameters:
entity
- The entity to which the component is attached.
-
getEntity
Get the entity to which this component belongs.- Returns:
- entity
-
setEnabled
public void setEnabled(boolean enabled)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.- Parameters:
enabled
- Should component be enabled
-
triggerUpdate
public final void triggerUpdate()Used to trigger the component to update itself. This should not need to be called manually. -
triggerEarlyUpdate
public final void triggerEarlyUpdate()Used to trigger the component to early-update itself. This should not need to be called manually. -
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-