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

    Fields 
    Modifier and Type Field Description
    protected boolean enabled  
    protected Entity entity  
  • 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

  • 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

      public void setEntity​(Entity entity)
      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

      public Entity 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 class java.lang.Object