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 TypeMethodDescriptionvoid
executeWhenLoaded
(AssetLoader<SpriteSheet> spriteSheetAssetLoader, Consumer<SolaImage> onSpriteLoaded) Executes the provided consumer asynchronously once the sprite for thisSpriteComponent
has been loaded.getSprite
(AssetLoader<SpriteSheet> spriteSheetAssetLoader) Returns anAssetHandle
for theSolaImage
of the sprite.@Nullable String
@Nullable String
void
setSpriteKeyFrame
(SpriteKeyFrame spriteKeyFrame) Updates theSpriteKeyFrame
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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 theSpriteSheet
assetspriteId
- 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
SpriteSheet
this sprite is in
-
getSpriteId
- Returns:
- the id for the sprite
-
setSpriteKeyFrame
Updates theSpriteKeyFrame
.- Parameters:
spriteKeyFrame
- the newSpriteKeyFrame
-
getSprite
Returns anAssetHandle
for theSolaImage
of the sprite.- Parameters:
spriteSheetAssetLoader
- theAssetLoader
forSpriteSheet
s- 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 thisSpriteComponent
has been loaded. This will execute immediately if the sprite is already loaded.- Parameters:
spriteSheetAssetLoader
- theAssetLoader
forSpriteSheet
sonSpriteLoaded
- the function to execute if the asset is loaded
-