com.annahid.libs.artenus.entities
EntityCollection
Provides a resizable list of Entity objects that implements Entity
, so it can
be added to a scene as a single entity. When added as an entity, it renders all contained
entities when its render method is called.
Entity collections have their own position, rotation, and scaling factors. The transformations of the entities added to a collection are relative to the global transformations of the collection. Effects in an entity collection are also added to the collection, and not to individual entities.
See Also:
public class EntityCollection extends ConcurrentCollection<Entity> implements Entity, Animatable, Touchable, Transformable, Renderable
Field Summary
Modifier and Type | Field and Description |
---|---|
protected | anim Holds the animation handler responsible for the collection as a whole. |
Constructor Summary
Modifier and Type | Constructor and Description |
---|---|
public | EntityCollection() Creates an EntityCollection. |
Method Summary
Modifier and Type | Method and Description |
---|---|
public boolean | add(Entity entity) Adds an element to the back of the collection. |
public void | advance(float elapsedTime) Advances the associated animation handler, and then advances all entities added to this
collection. |
public final boolean | bringToFront(Entity entity) Brings an entity to the end of its collection, causing it to appear above all other
entities. |
public void | clear() Clears all entities from this collection. |
public float | getAlpha() Gets the transparency value for this renderable. |
public AnimationHandler | getAnimation() Gets the animation handler currently affecting this animatable. |
public RGB | getColorFilter() Gets the color filter for this entity. |
public Point2D | getPosition() Gets the current position of this entity. |
public float | getRotation() Gets the current rotational angle of this entity. |
public Point2D | getScale() Gets the 2-dimensional scaling factor for this entity. |
protected Scene | getScene() Gets the scene this collection is currently attached to. |
public boolean | handleTouch(TouchEvent event) Called whenever a touch event arrives. |
public boolean | hasBehavior(Behaviors behavior) Indicates whether this entity has the specified behavior. |
public Iterator<Entity> | iterator() Returns a basic iterator over the elements. |
public void | move(float amountX, float amountY) Moves this entity the given distance. |
public void | onAttach(Scene scene) Called when this entity is associated with a scene. |
public void | onDetach(Scene scene) Called when this entity is dissociated with a scene. |
public void | prepend(Entity object) Inserts an element to the front of the collection. |
public Iterator<Entity> | recursiveIterator() Returns an iterator over the elements. |
public final boolean | recursiveRemove(Entity e) Removes an entity from this collection, searching recursively through all items. |
public void | render(RenderingContext ctx, int flags) Renders all the entities in the collection onto the given OpenGL context. |
public void | rotate(float angle) Rotates this entity the given number of degrees. |
public final boolean | sendToBack(Entity entity) Sends an entity to the beginning of its collection, causing it to be processed first and
displayed below all other entities. |
public void | setAlpha(float alpha) Sets the transparency value for this renderable. |
public void | setAnimation(AnimationHandler animation) Assigns an animation handler to handle animations for this animatable. |
public void | setColorFilter(float r, float g, float b) Sets the color filter for this entity. |
public void | setColorFilter(RGB rgb) Sets the color filter for this entity. |
public void | setPosition(Point2D position) Sets the position of this entity. |
public void | setPosition(float x, float y) Sets the position of this entity. |
public void | setRotation(float angle) Sets the rotational angle of this entity. |
public void | setScale(float scaleValue) Sets the scaling factor for this entity. |
public void | setScale(float scaleX, float scaleY) Sets the scaling factor for this entity, specifying different values horizontally and
vertically. |
Methods inherited from com.annahid.libs.artenus.data.ConcurrentCollection
add
, addAll
, clear
, contains
, containsAll
, getFirst
, getLast
, isEmpty
, iterator
, prepend
, remove
, removeAll
, retainAll
, size
, toArray
, toArray
Methods inherited from java.lang.Object
clone
, equals
, finalize
, getClass
, hashCode
, notify
, notifyAll
, toString
, wait
, wait
, wait
Field Detail
anim |
---|
protected anim Holds the animation handler responsible for the collection as a whole. |
Method Detail
add |
---|
public boolean add( Entity entity ) Adds an element to the back of the collection. Overrides:
Returns:
true |
advance | ||
---|---|---|
public void advance( float elapsedTime ) Advances the associated animation handler, and then advances all entities added to this
collection. Parameters:
Specified By:
|
bringToFront | ||
---|---|---|
public final boolean bringToFront( Entity entity ) Brings an entity to the end of its collection, causing it to appear above all other
entities. Entities in above collection will still cover the entity. Parameters:
|
clear |
---|
public void clear() Clears all entities from this collection. The collection will be empty. Overrides:
|
getAlpha |
---|
public float getAlpha() Gets the transparency value for this renderable. Specified By:
Returns:
The alpha value for transparency |
getAnimation |
---|
public AnimationHandler getAnimation() Gets the animation handler currently affecting this animatable. Specified By:
Returns:
Animation handler |
getColorFilter |
---|
public RGB getColorFilter() Gets the color filter for this entity. Modifying the fields in the returned value affects
the color filter. Specified By:
Returns:
The color filter |
getPosition |
---|
public Point2D getPosition() Gets the current position of this entity. Specified By:
Returns:
Current 2-dimensional position |
getRotation |
---|
public float getRotation() Gets the current rotational angle of this entity. Specified By:
Returns:
Rotational angle in degrees |
getScale |
---|
public Point2D getScale() Gets the 2-dimensional scaling factor for this entity. Specified By:
Returns:
The scaling factor over horizontal and vertical axes |
getScene |
---|
protected Scene getScene() Gets the scene this collection is currently attached to. Returns:
The scene |
handleTouch |
---|
public boolean handleTouch( TouchEvent event ) Called whenever a touch event arrives. Specified By:
Returns:
true if handled, false otherwise |
hasBehavior |
---|
public boolean hasBehavior( Behaviors behavior ) Indicates whether this entity has the specified behavior. If it does, it can be cast to the
corresponding interface. Note that the return value can be transient and a fixed return value
for a behavior is not guaranteed by the framework. Specified By:
Returns:
true if this entity has the behavior, false otherwise |
iterator |
---|
public Iterator<Entity> iterator() Returns a basic iterator over the elements. Overrides:
Returns:
An iterator over the elements in this list in proper sequence |
move |
---|
public void move( float amountX, float amountY ) Moves this entity the given distance. The translation will be relative to this entity's
current position. Specified By:
|
onAttach |
---|
public void onAttach( Scene scene ) Called when this entity is associated with a scene. Specified By:
|
onDetach |
---|
public void onDetach( Scene scene ) Called when this entity is dissociated with a scene. Specified By:
|
prepend |
---|
public void prepend( Entity object ) Inserts an element to the front of the collection. Overrides:
|
recursiveIterator |
---|
public Iterator<Entity> recursiveIterator() Returns an iterator over the elements. This iterator supports removal, like
iterator() . The main difference is that it does not only search the
items directly contained in this collection. Instead, it recognizes entity collections and
iterates recursively through them as well.Returns:
An iterator over the elements in this list and all sub-lists |
recursiveRemove | ||
---|---|---|
public final boolean recursiveRemove( Entity e ) Removes an entity from this collection, searching recursively through all items. The
difference between this method and remove(Object) is that this
method recognizes entity collections added to this collection, and beside considering
themselves, it searches recursively through them as well, until it finds e.Parameters:
Returns:
true if the entity is removed, and false if it doesn't exist in
this collection |
render |
---|
public void render( RenderingContext ctx, int flags ) Renders all the entities in the collection onto the given OpenGL context. Specified By:
render in Renderable |
rotate |
---|
public void rotate( float angle ) Rotates this entity the given number of degrees. This rotation will be relative to this
entity's current rotational angle. Specified By:
|
sendToBack | ||
---|---|---|
public final boolean sendToBack( Entity entity ) Sends an entity to the beginning of its collection, causing it to be processed first and
displayed below all other entities. Sprites in bottom layers will still be covered by the
sprite. Parameters:
|
setAlpha |
---|
public void setAlpha( float alpha ) Sets the transparency value for this renderable. An alpha value of 1 indicates a fully opaque
renderable and a value of 0 is an invisible sprite. Any value in between can be specified to
achieve transparency. Specified By:
|
setAnimation |
---|
public void setAnimation( AnimationHandler animation ) Assigns an animation handler to handle animations for this animatable. Specified By:
|
setColorFilter |
---|
public void setColorFilter( float r, float g, float b ) Sets the color filter for this entity. The original colors should be multiplied by this color
when rendering. Specified By:
|
setColorFilter |
---|
public void setColorFilter( RGB rgb ) Sets the color filter for this entity. The original colors should be multiplied by this color
when rendering. Specified By:
|
setPosition |
---|
public void setPosition( Point2D position ) Sets the position of this entity. Specified By:
|
setPosition |
---|
public void setPosition( float x, float y ) Sets the position of this entity. Specified By:
|
setRotation |
---|
public void setRotation( float angle ) Sets the rotational angle of this entity. Specified By:
|
setScale |
---|
public void setScale( float scaleValue ) Sets the scaling factor for this entity. Horizontal and vertical scaling factors will be set
to the same value. Specified By:
|
setScale |
---|
public void setScale( float scaleX, float scaleY ) Sets the scaling factor for this entity, specifying different values horizontally and
vertically. Specified By:
|