Module hanyaeger

Class CompositeEntity

All Implemented Interfaces:
Rotatable, Effectable, Anchorable, Bounded, DragRepositoryAccessor, EventInitiator, GameNode, Placeable, Removable, SceneChild, Initializable, com.github.hanyaeger.core.scenes.DimensionsProvider, TimerListProvider
Direct Known Subclasses:
DynamicCompositeEntity

public abstract class CompositeEntity extends YaegerEntity
When a group of entities is combined to create a single YaegerEntity, they are a composition and this class should be used to perform that composition.

It is possible to add instances of YaegerEntity to this CompositeEntity, which ensures their behavior is managed by this CompositeEntity. They are still part of the YaegerScene as any other YaegerEntity, but are managed as a whole.

This means that this CompositeEntity has its own coordinate system, meaning (0,0) is the origin of this CompositeEntity. The width and height is hence calculated, based on its content. This is done only at initialization, so removing Entities from this CompositeEntity after initialization, does nog change its width or height.

Removing Entities from this CompositeEntity removes them as expected. Removing the entire CompositeEntity, also removes all Entities that are part of the composition.

A CompositeEntity does not listen to a Game World Update, but its children still can. In such a case the children receive their Updatable.update(long), and can act accordingly, but the CompositeEntity itself will not so. If such behavior is required, use a DynamicCompositeEntity, which receives its own Updatable.update(long).

  • Constructor Details

    • CompositeEntity

      protected CompositeEntity(Coordinate2D initialLocation)
      Create a new CompositeEntity on the given initialLocation.
      Parameters:
      initialLocation - the initial position at which this CompositeEntity should be placed
  • Method Details

    • addEntity

      protected void addEntity(YaegerEntity yaegerEntity)
      Add an YaegerEntity to this YaegerScene.

      This method can only be used to add an instance of YaegerEntity during initialisation.If one should be added during the game, a EntitySpawner should be used.

      Parameters:
      yaegerEntity - The YaegerEntity to be added
    • setupEntities

      protected abstract void setupEntities()
      Implement this method to set up all instances of YaegerEntity that should be added to the CompositeEntity before activation.
    • beforeInitialize

      public void beforeInitialize()
      Description copied from interface: Initializable
      A default method to be used as a lifecycle hook to be called before a YaegerEntity is initialized and added to the YaegerScene.

      By default, this method is empty.

    • init

      public void init(com.google.inject.Injector injector)
      Specified by:
      init in interface Initializable
      Overrides:
      init in class YaegerEntity
      Parameters:
      injector - the Injector used for Dependency Injection

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

    • applyTranslationsForAnchorPoint

      public void applyTranslationsForAnchorPoint()
      At this stage we only ask the children to apply their transformation. The transformation that should be applied to this CompositeEntity can only be applied after its children have been added to the Group and the Group has been added to the Scene.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Overrides:
      applyTranslationsForAnchorPoint in class YaegerEntity
    • applyEntityProcessor

      public void applyEntityProcessor(EntityProcessor processor)
      Description copied from class: YaegerEntity
      Apply an EntityProcessor to this YaegerEntity. An EntityProcessor is most likely a lambda expression passed by a parent object.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Overrides:
      applyEntityProcessor in class YaegerEntity
      Parameters:
      processor - an instance of EntityProcessor, most likely a lambda expression that should be called for processing this YaegerEntity
    • addToParent

      public void addToParent(EntityProcessor processor)
      Note that this method will become recursive if the composition consists of more instance of CompositeEntity.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Overrides:
      addToParent in class YaegerEntity
      Parameters:
      processor - an instance of EntityProcessor, most likely a lambda expression that can be used for adding this node as a child to a parent node
    • setAnchorLocation

      public void setAnchorLocation(Coordinate2D anchorLocation)
      Description copied from interface: Placeable
      Set the Coordinate2D where the AnchorPoint of this YaegerEntity will be placed, within the YaegerScene.
      Specified by:
      setAnchorLocation in interface Placeable
      Overrides:
      setAnchorLocation in class YaegerEntity
      Parameters:
      anchorLocation - the Coordinate2D that should be used
    • getNode

      public Optional<javafx.scene.Node> getNode()
      Description copied from interface: GameNode
      Return an Optional of the Node that is related to this GameNode.
      Returns:
      an Optional of the Node that is related to this GameNode
    • setRootPane

      public void setRootPane(javafx.scene.layout.Pane rootPane)
      Description copied from class: YaegerEntity
      Set the root pane to which this YaegerEntity is added.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Overrides:
      setRootPane in class YaegerEntity
      Parameters:
      rootPane - the root pane, which is an instance of Pane
    • setGroup

      @Inject public void setGroup(javafx.scene.Group group)
      Set the Group that is used within this CompositeEntity. All instances of YaegerEntity that are added to this CompositeEntity are packaged together within this Group. Within it, they have their own coordinate-space and can be placed as a whole on the YaegerScene.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Parameters:
      group - the Group to be used
    • attachEventListener

      public void attachEventListener(javafx.event.EventType eventType, javafx.event.EventHandler eventHandler)
      Description copied from interface: EventInitiator
      Attach an EventHandler for the given EventType.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Specified by:
      attachEventListener in interface EventInitiator
      Overrides:
      attachEventListener in class YaegerEntity
      Parameters:
      eventType - the EventType that should trigger the given EventHandler
      eventHandler - the EventHandler that should be called whenever an event of type EventType occurs
    • transferCoordinatesToNode

      public void transferCoordinatesToNode()
      Because the Group encapsulates the child nodes and its BoundingBox depends on the space and location of those child nodes, first the child nodes receive their coordinates and transformations. After this the Group node does the same.

      Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.

      Specified by:
      transferCoordinatesToNode in interface Placeable
      Overrides:
      transferCoordinatesToNode in class YaegerEntity
    • remove

      public void remove()
      Description copied from interface: Removable
      Perform all necessary actions to remove the entity.
      Specified by:
      remove in interface Removable
      Overrides:
      remove in class YaegerEntity