Module hanyaeger

Class SpriteEntity

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

public abstract class SpriteEntity extends YaegerEntity implements ResourceConsumer
A SpriteEntity is a YaegerEntity that is represented by an Image. When creating a SpriteEntity, the Size of the image must be passed through the constructor. After construction, this Size can not be changed.
  • Constructor Details

    • SpriteEntity

      protected SpriteEntity(String resource, Coordinate2D initialLocation)
      Instantiate a new SpriteEntity for an image with the given resource. This SpriteEntity will use the original dimensions of the image.
      Parameters:
      resource - the url of the image file. Relative to the resources folder
      initialLocation - the initial Coordinate2D of this SpriteEntity
    • SpriteEntity

      protected SpriteEntity(String resource, Coordinate2D initialLocation, int rows, int columns)
      Instantiate a new SpriteEntity for a given image.
      Parameters:
      resource - the url of the image file. Relative to the resources folder
      initialLocation - the initial Coordinate2D of this SpriteEntity
      rows - the number of rows the image contains
      columns - the number of columns the image contains
    • SpriteEntity

      protected SpriteEntity(String resource, Coordinate2D initialLocation, Size size)
      Instantiate a new SpriteEntity for a given image.
      Parameters:
      resource - the url of the image file. Relative to the resources folder
      initialLocation - the initial Coordinate2D of this SpriteEntity
      size - the bounding box of this SpriteEntity
    • SpriteEntity

      protected SpriteEntity(String resource, Coordinate2D initialLocation, Size size, int rows, int columns)
      Instantiate a new SpriteEntity for a given image.
      Parameters:
      resource - the url of the image file. Relative to the resources folder
      initialLocation - the initial Coordinate2D of this SpriteEntity
      size - the bounding box of this SpriteEntity
      rows - the number of rows the image contains
      columns - the number of columns the image contains
  • Method Details

    • 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.

    • setCurrentFrameIndex

      public void setCurrentFrameIndex(int index)
      Set the current frame index of the Sprite image.
      Parameters:
      index - the index that should be shown. The index is zero based and increases from left to right. When the last index is reached, the index will wrap to the next row. The frame modulo index will be shown
    • getCurrentFrameIndex

      public int getCurrentFrameIndex()
      Return the current index of the sprite.
      Returns:
      the index of the sprite as an int
    • setPreserveAspectRatio

      public void setPreserveAspectRatio(boolean preserveAspectRatio)
      Preserve the aspect ratio of the width and height of this SpriteEntity.
      Parameters:
      preserveAspectRatio - true if the ratio should be preserved, false otherwise
    • getFrames

      protected int getFrames()
      Return the number of frames comprising this SpriteEntity.
      Returns:
      the number of frames as an int
    • getNode

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

      public final 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
    • setAnchorLocation

      public final 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
    • setSpriteAnimationDelegateFactory

      @Inject public void setSpriteAnimationDelegateFactory(SpriteAnimationDelegateFactory spriteAnimationDelegateFactory)
      Set the SpriteAnimationDelegateFactory to be used.

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

      Parameters:
      spriteAnimationDelegateFactory - an instance of SpriteAnimationDelegateFactory
    • setImageRepository

      @Inject public void setImageRepository(ImageRepository imageRepository)
      Set the ImageRepository to be used.

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

      Parameters:
      imageRepository - an instance of ImageRepository
    • setImageViewFactory

      @Inject public void setImageViewFactory(ImageViewFactory imageViewFactory)
      Set the ImageViewFactory to be used.

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

      Parameters:
      imageViewFactory - an instance of ImageViewFactory