Module technology.sola.engine
Class SpriteComponent
java.lang.Object
technology.sola.engine.graphics.components.SpriteComponent
- All Implemented Interfaces:
technology.sola.ecs.Component
SpriteComponent is a
Component that contains data for rendering 2d sprites for an
Entity.-
Constructor Summary
ConstructorsConstructorDescriptionSpriteComponent(String spriteSheetId, String spriteId) Creates a SpriteComponent for a sprite sheet and sprite id.SpriteComponent(SolaImage solaImage) Creates a SpriteComponent from aSolaImage.SpriteComponent(SpriteKeyFrame spriteKeyFrame) Creates a SpriteComponent from aSpriteKeyFrame. -
Method Summary
Modifier and TypeMethodDescriptionvoidexecuteWhenLoaded(AssetLoader<SpriteSheet> spriteSheetAssetLoader, Consumer<SolaImage> onSpriteLoaded) Executes the provided consumer asynchronously once the sprite for thisSpriteComponenthas been loaded.getSprite(AssetLoader<SpriteSheet> spriteSheetAssetLoader) Returns anAssetHandlefor theSolaImageof the sprite.@Nullable String@Nullable StringvoidsetSpriteKeyFrame(SpriteKeyFrame spriteKeyFrame) Updates theSpriteKeyFrame.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface technology.sola.ecs.Component
afterDeserialize
-
Constructor Details
-
SpriteComponent
Creates a SpriteComponent for a sprite sheet and sprite id.- Parameters:
spriteSheetId- the id for theSpriteSheetassetspriteId- the id for the sprite
-
SpriteComponent
Creates a SpriteComponent from aSpriteKeyFrame.- Parameters:
spriteKeyFrame- the sprite's key frame
-
SpriteComponent
Creates a SpriteComponent from aSolaImage.- Parameters:
solaImage- the image for the sprite
-
-
Method Details
-
getSpriteSheetId
- Returns:
- the id of the
SpriteSheetthis sprite is in
-
getSpriteId
- Returns:
- the id for the sprite
-
setSpriteKeyFrame
Updates theSpriteKeyFrame.- Parameters:
spriteKeyFrame- the newSpriteKeyFrame
-
getSprite
Returns anAssetHandlefor theSolaImageof the sprite.- Parameters:
spriteSheetAssetLoader- theAssetLoaderforSpriteSheets- Returns:
- the
AssetHandlefor the sprite
-
executeWhenLoaded
public void executeWhenLoaded(AssetLoader<SpriteSheet> spriteSheetAssetLoader, Consumer<SolaImage> onSpriteLoaded) Executes the provided consumer asynchronously once the sprite for thisSpriteComponenthas been loaded. This will execute immediately if the sprite is already loaded.- Parameters:
spriteSheetAssetLoader- theAssetLoaderforSpriteSheetsonSpriteLoaded- the function to execute if the asset is loaded
-