java.lang.Object
technology.sola.engine.graphics.components.SpriteComponent
All Implemented Interfaces:
technology.sola.ecs.Component

@NullMarked public class SpriteComponent extends Object implements technology.sola.ecs.Component
SpriteComponent is a Component that contains data for rendering 2d sprites for an Entity.
  • Constructor Details

    • SpriteComponent

      public SpriteComponent(String spriteSheetId, String spriteId)
      Creates a SpriteComponent for a sprite sheet and sprite id.
      Parameters:
      spriteSheetId - the id for the SpriteSheet asset
      spriteId - the id for the sprite
    • SpriteComponent

      public SpriteComponent(SpriteKeyFrame spriteKeyFrame)
      Creates a SpriteComponent from a SpriteKeyFrame.
      Parameters:
      spriteKeyFrame - the sprite's key frame
    • SpriteComponent

      public SpriteComponent(SolaImage solaImage)
      Creates a SpriteComponent from a SolaImage.
      Parameters:
      solaImage - the image for the sprite
  • Method Details

    • getSpriteSheetId

      public @Nullable String getSpriteSheetId()
      Returns:
      the id of the SpriteSheet this sprite is in
    • getSpriteId

      public @Nullable String getSpriteId()
      Returns:
      the id for the sprite
    • setSpriteKeyFrame

      public void setSpriteKeyFrame(SpriteKeyFrame spriteKeyFrame)
      Updates the SpriteKeyFrame.
      Parameters:
      spriteKeyFrame - the new SpriteKeyFrame
    • getSprite

      public AssetHandle<SolaImage> getSprite(AssetLoader<SpriteSheet> spriteSheetAssetLoader)
      Returns an AssetHandle for the SolaImage of the sprite.
      Parameters:
      spriteSheetAssetLoader - the AssetLoader for SpriteSheets
      Returns:
      the AssetHandle for the sprite
    • executeWhenLoaded

      public void executeWhenLoaded(AssetLoader<SpriteSheet> spriteSheetAssetLoader, Consumer<SolaImage> onSpriteLoaded)
      Executes the provided consumer asynchronously once the sprite for this SpriteComponent has been loaded. This will execute immediately if the sprite is already loaded.
      Parameters:
      spriteSheetAssetLoader - the AssetLoader for SpriteSheets
      onSpriteLoaded - the function to execute if the asset is loaded