Class Entity2DContainer

java.lang.Object
com.xebisco.yield.AbstractBehavior
com.xebisco.yield.Entity2DContainer
All Implemented Interfaces:
Behavior, Renderable, Closeable, AutoCloseable
Direct Known Subclasses:
Entity2D, Scene

public class Entity2DContainer extends AbstractBehavior implements Renderable
This is a class that represents a container for Entity2Ds, allowing for instantiation and removal of entities.
  • Constructor Details

    • Entity2DContainer

      public Entity2DContainer(Application application)
      Constructs a new instance of Entity2DContainer with the given application.
      Parameters:
      application - the application that this Entity2DContainer belongs to
  • Method Details

    • instantiate

      public Entity2D instantiate(Entity2DPrefab prefab, EntityStarter entityStarter)
      This function instantiates a Entity2D using a prefab and its components, sets its tags and parent, adds it to a list of entities, and starts it.
      Parameters:
      prefab - The prefab parameter is an instance of the Entity2DPrefab class, which contains information about the components and children of the entity to be instantiated.
      entityStarter - entityStarter is an optional parameter of type EntityStarter, which is an interface that defines a method called "start" that takes an Entity2D object as a parameter. This parameter allows for additional functionality to be executed on the instantiated entity after it has been created.
      Returns:
      The method is returning an instance of the Entity2D class.
    • onStart

      public void onStart()
      Description copied from interface: Behavior
      This method is called when the behavior is started. It is typically used to initialize any necessary state or resources.
      Specified by:
      onStart in interface Behavior
    • render

      public void render(Renderer renderer)
      Description copied from interface: Renderable
      Renders the object using the provided Renderer.
      Specified by:
      render in interface Renderable
      Parameters:
      renderer - The renderer to use for rendering the object.
    • onUpdate

      public void onUpdate(ContextTime time)
      Description copied from interface: Behavior
      This method is called when the behavior needs to be updated with the current time. It is typically used to perform any necessary calculations or updates based on the current time.
      Specified by:
      onUpdate in interface Behavior
      Parameters:
      time - The current time context.
    • instantiate

      public Entity2D instantiate(Entity2DPrefab prefab)
      This function instantiates a 2D entity using a prefab and returns it.
      Parameters:
      prefab - The prefab parameter is an instance of the Entity2DPrefab class, which contains information about the components and children of the entity to be instantiated.
      Returns:
      The method is returning an instance of the Entity2D class.
    • remove

      public boolean remove(Entity2D entity) throws IOException
      Removes the specified entity from the container and adds it to the list of entities to be removed.
      Parameters:
      entity - The entity to be removed
      Returns:
      true if the entity was successfully added to the list of entities to be removed, false otherwise
      Throws:
      IOException - if an error occurs while closing the entity
    • application

      public Application application()
      Returns the application that this Entity2DContainer belongs to.
      Returns:
      the application
    • entities

      public List<Entity2D> entities()
      Returns the list of entities in the container.
      Returns:
      the list of entities
    • setEntities

      public Entity2DContainer setEntities(List<Entity2D> entities)
      Sets the list of entities in the container.
      Parameters:
      entities - the list of entities to be set
      Returns:
      this Entity2DContainer instance for method chaining.
    • toAddEntities

      public Set<Entity2D> toAddEntities()
      Returns the set of entities to be added to the container.
      Returns:
      the set of entities to be added
    • toRemoveEntities

      public Set<Entity2D> toRemoveEntities()
      Returns the set of entities to be removed from the container.
      Returns:
      the set of entities to be removed
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException