java.lang.Object
com.github.hanyaeger.core.YaegerGameObject
com.github.hanyaeger.api.entities.YaegerEntity
com.github.hanyaeger.api.entities.impl.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
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.-
Field Summary
Fields inherited from class com.github.hanyaeger.core.YaegerGameObject
colorAdjust
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SpriteEntity
(String resource, Coordinate2D initialLocation) Instantiate a newSpriteEntity
for an image with the givenresource
.protected
SpriteEntity
(String resource, Coordinate2D initialLocation, int rows, int columns) Instantiate a newSpriteEntity
for a given image.protected
SpriteEntity
(String resource, Coordinate2D initialLocation, Size size) Instantiate a newSpriteEntity
for a given image.protected
SpriteEntity
(String resource, Coordinate2D initialLocation, Size size, int rows, int columns) Instantiate a newSpriteEntity
for a given image. -
Method Summary
Modifier and TypeMethodDescriptionint
Return the current index of the sprite.protected int
Return the number of frames comprising thisSpriteEntity
.Optional
<? extends javafx.scene.Node> getNode()
void
init
(com.google.inject.Injector injector) final void
remove()
Perform all necessary actions to remove the entity.final void
setAnchorLocation
(Coordinate2D anchorLocation) Set theCoordinate2D
where theAnchorPoint
of thisYaegerEntity
will be placed, within theYaegerScene
.void
setCurrentFrameIndex
(int index) Set the current frame index of the Sprite image.void
setImageRepository
(ImageRepository imageRepository) Set theImageRepository
to be used.void
setImageViewFactory
(ImageViewFactory imageViewFactory) Set theImageViewFactory
to be used.void
setPreserveAspectRatio
(boolean preserveAspectRatio) Preserve the aspect ratio of the width and height of thisSpriteEntity
.void
setSpriteAnimationDelegateFactory
(SpriteAnimationDelegateFactory spriteAnimationDelegateFactory) Set theSpriteAnimationDelegateFactory
to be used.Methods inherited from class com.github.hanyaeger.api.entities.YaegerEntity
addToEntityCollection, addToParent, angleTo, angleTo, applyEntityProcessor, applyTranslationsForAnchorPoint, attachEventListener, distanceTo, distanceTo, getAnchorLocation, getAnchorPoint, getCursor, getDragNDropRepository, getInitializationBuffer, getLocationInScene, getOpacity, getRootPane, getSceneHeight, getSceneWidth, getTimers, getViewOrder, isVisible, setAnchorLocationX, setAnchorLocationY, setAnchorPoint, setCursor, setDragNDropRepository, setOpacity, setRootPane, setViewOrder, setVisible, transferCoordinatesToNode
Methods inherited from class com.github.hanyaeger.core.YaegerGameObject
getBrightness, getContrast, getHue, getSaturation, setBrightness, setContrast, setHue, setSaturation
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.github.hanyaeger.core.entities.Bounded
getBoundingBox, getHeight, getWidth
Methods inherited from interface com.github.hanyaeger.core.Initializable
beforeInitialize
Methods inherited from interface com.github.hanyaeger.core.entities.Removable
notifyRemove
Methods inherited from interface com.github.hanyaeger.core.ResourceConsumer
createPathForResource
Methods inherited from interface com.github.hanyaeger.api.entities.Rotatable
getRotation, setRotate
-
Constructor Details
-
SpriteEntity
Instantiate a newSpriteEntity
for an image with the givenresource
. ThisSpriteEntity
will use the original dimensions of the image.- Parameters:
resource
- the url of the image file. Relative to the resources folderinitialLocation
- the initialCoordinate2D
of thisSpriteEntity
-
SpriteEntity
Instantiate a newSpriteEntity
for a given image.- Parameters:
resource
- the url of the image file. Relative to the resources folderinitialLocation
- the initialCoordinate2D
of thisSpriteEntity
rows
- the number of rows the image containscolumns
- the number of columns the image contains
-
SpriteEntity
Instantiate a newSpriteEntity
for a given image.- Parameters:
resource
- the url of the image file. Relative to the resources folderinitialLocation
- the initialCoordinate2D
of thisSpriteEntity
size
- the bounding box of thisSpriteEntity
-
SpriteEntity
protected SpriteEntity(String resource, Coordinate2D initialLocation, Size size, int rows, int columns) Instantiate a newSpriteEntity
for a given image.- Parameters:
resource
- the url of the image file. Relative to the resources folderinitialLocation
- the initialCoordinate2D
of thisSpriteEntity
size
- the bounding box of thisSpriteEntity
rows
- the number of rows the image containscolumns
- the number of columns the image contains
-
-
Method Details
-
init
public void init(com.google.inject.Injector injector) - Specified by:
init
in interfaceInitializable
- Overrides:
init
in classYaegerEntity
- Parameters:
injector
- theInjector
used for Dependency InjectionNote: 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 thisSpriteEntity
.- Parameters:
preserveAspectRatio
-true
if the ratio should be preserved,false
otherwise
-
getFrames
protected int getFrames()Return the number of frames comprising thisSpriteEntity
.- Returns:
- the number of frames as an
int
-
getNode
Description copied from interface:GameNode
-
remove
public final void remove()Description copied from interface:Removable
Perform all necessary actions to remove the entity.- Specified by:
remove
in interfaceRemovable
- Overrides:
remove
in classYaegerEntity
-
setAnchorLocation
Description copied from interface:Placeable
Set theCoordinate2D
where theAnchorPoint
of thisYaegerEntity
will be placed, within theYaegerScene
.- Specified by:
setAnchorLocation
in interfacePlaceable
- Overrides:
setAnchorLocation
in classYaegerEntity
- Parameters:
anchorLocation
- theCoordinate2D
that should be used
-
setSpriteAnimationDelegateFactory
@Inject public void setSpriteAnimationDelegateFactory(SpriteAnimationDelegateFactory spriteAnimationDelegateFactory) Set theSpriteAnimationDelegateFactory
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 ofSpriteAnimationDelegateFactory
-
setImageRepository
Set theImageRepository
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 ofImageRepository
-
setImageViewFactory
Set theImageViewFactory
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 ofImageViewFactory
-