Package ecs

Class GameObject

java.lang.Object
ecs.GameObject

public class GameObject extends Object
A GameObject is the root of the Entity Component system used to store all entities in Azurite games. Each GameObject can contain any of a number of available components including spriteRenderers and lights. By default, each GameObject contains a Transform, which holds the X and Y position, and width and height of the object in pixels.
Author:
Asher Haun, Gabe, Juyas
  • Field Details

  • Constructor Details

    • GameObject

      public GameObject(String name, List<Component> componentList, org.joml.Vector2f position, int zIndex)
      Creates a new GameObject.
      Parameters:
      name -
      componentList -
      position -
      zIndex -
    • GameObject

      public GameObject(Scene scene, String name, org.joml.Vector2f position, int zIndex)
      Creates a new GameObject.
      Parameters:
      scene - the scene to add the GameObject to. By default, GameObjects are added to the currentScene.
      name - name of the GameObject
      position -
      zIndex -
    • GameObject

      public GameObject(String name, org.joml.Vector2f position, int zIndex)
      Parameters:
      name -
      position -
      zIndex -
    • GameObject

      public GameObject(String name, int zIndex)
      Parameters:
      name -
      zIndex -
    • GameObject

      public GameObject(org.joml.Vector2f position, int zIndex)
      Parameters:
      position -
      zIndex -
    • GameObject

      public GameObject(org.joml.Vector2f position)
      Parameters:
      position -
  • Method Details

    • start

      public void start()
      Called once on gameObject creation, also starts any components that are passed to the constructor.
    • update

      public void update(float dt)
      Called once every frame for each GameObject, calls the update method for each component it contains
    • getParentScene

      public Scene getParentScene()
      Returns:
      the parent scene of this gameObject
    • getUniqueId

      public long getUniqueId()
      Returns:
      the universal and unique id among all objects
    • getReadOnlyPosition

      public org.joml.Vector2f getReadOnlyPosition()
    • getPositionData

      public float[] getPositionData()
    • zIndex

      public int zIndex()
    • setZIndex

      @Deprecated public void setZIndex(int z)
      Deprecated.
    • name

      public String name()
    • getComponent

      public <T> T getComponent(Class<T> componentClass)
      Takes a parameter of a class that extends component and returns it if it is contained in the GameObject's list of components.
      Parameters:
      componentClass - of component (ie. "SpriteRenderer.class")
      Returns:
      Component of type passed as param is contained in GameObject
    • getComponents

      public <T> List<T> getComponents(Class<T> componentClass)
      Takes a parameter of a class that extends component and returns it if it is contained in the GameObject's list of components.
      Parameters:
      componentClass - of component (ie. "SpriteRenderer.class")
      Returns:
      all components of type passed as param is contained in GameObject
    • removeComponent

      public <T> void removeComponent(Class<T> componentClass)
      Takes a parameter of a class that extends component and removed it from the GameObject if it is contained in the list of components.
      Parameters:
      componentClass - of component (ie. "SpriteRenderer.class")
    • addComponent

      public GameObject addComponent(Component c)
      Adds a new component to the GameObject's list.
      Parameters:
      c - the new component
      Returns:
      the gameobject itself
    • getComponents

      public List<Component> getComponents()
      Returns:
      List of Components in GameObject