- All Implemented Interfaces:
Rotatable
,Effectable
,Anchorable
,Bounded
,DragRepositoryAccessor
,EventInitiator
,GameNode
,Placeable
,Removable
,SceneChild
,Initializable
,com.github.hanyaeger.core.scenes.DimensionsProvider
,TimerListProvider
- Direct Known Subclasses:
DynamicCompositeEntity
YaegerEntity
, they are
a composition and this class should be used to perform that composition.
It is possible to add instances of YaegerEntity
to this CompositeEntity
,
which ensures their behavior is managed by this CompositeEntity
. They are still
part of the YaegerScene
as any other
YaegerEntity
, but are managed as a whole.
This means that this CompositeEntity
has its own coordinate system, meaning (0,0) is the
origin of this CompositeEntity
. The width and height is hence calculated, based on its content.
This is done only at initialization, so removing Entities from this CompositeEntity
after
initialization, does nog change its width or height.
Removing Entities from this CompositeEntity
removes them as expected. Removing the entire
CompositeEntity
, also removes all Entities that are part of the composition.
A CompositeEntity
does not listen to a Game World Update, but its children still can. In such a case
the children receive their Updatable.update(long)
, and can act accordingly,
but the CompositeEntity
itself will not so. If such behavior is required, use a DynamicCompositeEntity
,
which receives its own Updatable.update(long)
.
-
Field Summary
Fields inherited from class com.github.hanyaeger.core.YaegerGameObject
colorAdjust
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CompositeEntity
(Coordinate2D initialLocation) Create a newCompositeEntity
on the giveninitialLocation
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addEntity
(YaegerEntity yaegerEntity) Add anYaegerEntity
to thisYaegerScene
.void
addToParent
(EntityProcessor processor) Note that this method will become recursive if the composition consists of more instance ofCompositeEntity
.void
applyEntityProcessor
(EntityProcessor processor) Apply anEntityProcessor
to thisYaegerEntity
.void
At this stage we only ask the children to apply their transformation.void
attachEventListener
(javafx.event.EventType eventType, javafx.event.EventHandler eventHandler) Attach anEventHandler
for the givenEventType
.void
A default method to be used as a lifecycle hook to be called before aYaegerEntity
is initialized and added to theYaegerScene
.Optional
<javafx.scene.Node> getNode()
void
init
(com.google.inject.Injector injector) void
remove()
Perform all necessary actions to remove the entity.void
setAnchorLocation
(Coordinate2D anchorLocation) Set theCoordinate2D
where theAnchorPoint
of thisYaegerEntity
will be placed, within theYaegerScene
.void
setGroup
(javafx.scene.Group group) Set theGroup
that is used within thisCompositeEntity
.void
setRootPane
(javafx.scene.layout.Pane rootPane) Set the root pane to which thisYaegerEntity
is added.protected abstract void
Implement this method to set up all instances ofYaegerEntity
that should be added to theCompositeEntity
before activation.void
Because theGroup
encapsulates the child nodes and itsBoundingBox
depends on the space and location of those child nodes, first the child nodes receive their coordinates and transformations.Methods inherited from class com.github.hanyaeger.api.entities.YaegerEntity
addToEntityCollection, angleTo, angleTo, distanceTo, distanceTo, getAnchorLocation, getAnchorPoint, getCursor, getDragNDropRepository, getInitializationBuffer, getLocationInScene, getOpacity, getRootPane, getSceneHeight, getSceneWidth, getTimers, getViewOrder, isVisible, setAnchorLocationX, setAnchorLocationY, setAnchorPoint, setCursor, setDragNDropRepository, setOpacity, setViewOrder, setVisible
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.entities.Removable
notifyRemove
Methods inherited from interface com.github.hanyaeger.api.entities.Rotatable
getRotation, setRotate
-
Constructor Details
-
CompositeEntity
Create a newCompositeEntity
on the giveninitialLocation
.- Parameters:
initialLocation
- the initial position at which thisCompositeEntity
should be placed
-
-
Method Details
-
addEntity
Add anYaegerEntity
to thisYaegerScene
.This method can only be used to add an instance of
YaegerEntity
during initialisation.If one should be added during the game, aEntitySpawner
should be used.- Parameters:
yaegerEntity
- TheYaegerEntity
to be added
-
setupEntities
protected abstract void setupEntities()Implement this method to set up all instances ofYaegerEntity
that should be added to theCompositeEntity
before activation. -
beforeInitialize
public void beforeInitialize()Description copied from interface:Initializable
A default method to be used as a lifecycle hook to be called before aYaegerEntity
is initialized and added to theYaegerScene
.By default, this method is empty.
-
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.
-
applyTranslationsForAnchorPoint
public void applyTranslationsForAnchorPoint()At this stage we only ask the children to apply their transformation. The transformation that should be applied to thisCompositeEntity
can only be applied after its children have been added to theGroup
and theGroup
has been added to theScene
.Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.
- Overrides:
applyTranslationsForAnchorPoint
in classYaegerEntity
-
applyEntityProcessor
Description copied from class:YaegerEntity
Apply anEntityProcessor
to thisYaegerEntity
. AnEntityProcessor
is most likely a lambda expression passed by a parent object.Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.
- Overrides:
applyEntityProcessor
in classYaegerEntity
- Parameters:
processor
- an instance ofEntityProcessor
, most likely a lambda expression that should be called for processing thisYaegerEntity
-
addToParent
Note that this method will become recursive if the composition consists of more instance ofCompositeEntity
.Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.
- Overrides:
addToParent
in classYaegerEntity
- Parameters:
processor
- an instance ofEntityProcessor
, most likely a lambda expression that can be used for adding this node as a child to a parent node
-
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
-
getNode
Description copied from interface:GameNode
-
setRootPane
public void setRootPane(javafx.scene.layout.Pane rootPane) Description copied from class:YaegerEntity
Set the root pane to which thisYaegerEntity
is added.Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.
- Overrides:
setRootPane
in classYaegerEntity
- Parameters:
rootPane
- the root pane, which is an instance ofPane
-
setGroup
@Inject public void setGroup(javafx.scene.Group group) Set theGroup
that is used within thisCompositeEntity
. All instances ofYaegerEntity
that are added to thisCompositeEntity
are packaged together within thisGroup
. Within it, they have their own coordinate-space and can be placed as a whole on theYaegerScene
.Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.
- Parameters:
group
- theGroup
to be used
-
attachEventListener
public void attachEventListener(javafx.event.EventType eventType, javafx.event.EventHandler eventHandler) Description copied from interface:EventInitiator
Attach anEventHandler
for the givenEventType
.Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.
- Specified by:
attachEventListener
in interfaceEventInitiator
- Overrides:
attachEventListener
in classYaegerEntity
- Parameters:
eventType
- theEventType
that should trigger the givenEventHandler
eventHandler
- theEventHandler
that should be called whenever an event of typeEventType
occurs
-
transferCoordinatesToNode
public void transferCoordinatesToNode()Because theGroup
encapsulates the child nodes and itsBoundingBox
depends on the space and location of those child nodes, first the child nodes receive their coordinates and transformations. After this theGroup
node does the same.Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.
- Specified by:
transferCoordinatesToNode
in interfacePlaceable
- Overrides:
transferCoordinatesToNode
in classYaegerEntity
-
remove
public void remove()Description copied from interface:Removable
Perform all necessary actions to remove the entity.- Specified by:
remove
in interfaceRemovable
- Overrides:
remove
in classYaegerEntity
-