com.annahid.libs.artenus.graphics.sprites
SpriteEntity
Superclass for all sprites. A sprite is a mobile piece of graphic that can represent an object in
the game. Sprites are the graphical entities that are used in scenes. They can be moved, rotated,
scaled and animated according to their role in the game.
See Also:
public abstract class SpriteEntity implements Entity, Animatable, Renderable, Transformable
Field Summary
Modifier and Type | Field and Description |
---|---|
protected | alpha Holds the alpha transparency value for this sprite. |
protected | anim Holds the animation currently applied to this sprite. |
protected final | cf Holds color filter currently applied to this sprite. |
protected final | pos Holds current position of this sprite. |
protected | rotation Holds the rotational angle. |
protected final | scale Holds scaling factor in both dimensions. |
Constructor Summary
Modifier and Type | Constructor and Description |
---|---|
protected | SpriteEntity() Called by subclasses to initialize the sprite. |
Method Summary
Modifier and Type | Method and Description |
---|---|
public void | advance(float elapsedTime) Advances the animation for this sprite. |
public final float | getAlpha() Gets the transparency value for this sprite. |
public final AnimationHandler | getAnimation() Gets the current animation handler assigned to this sprite. |
public final RGB | getColorFilter() Gets the color filter for this sprite. |
public final Point2D | getPosition() Gets the current position of this entity. |
public final float | getRotation() Gets the current rotational angle of this entity. |
public final Point2D | getScale() Gets the 2-dimensional scaling factor for this sprite. |
public boolean | hasBehavior(Behaviors behavior) Indicates whether this entity has the specified behavior. |
public final void | move(float amountX, float amountY) Moves this sprite 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 final void | rotate(float angle) Rotates this sprite the given number of degrees. |
public final void | setAlpha(float alphaValue) Sets the transparency value for this sprite. |
public final void | setAnimation(AnimationHandler animation) Sets the animation handler for this sprite. |
public final void | setColorFilter(float r, float g, float b) Sets the color filter for this sprite. |
public final void | setColorFilter(RGB rgb) Sets the color filter for this sprite. |
public final void | setPosition(Point2D position) Sets the position of this sprite. |
public void | setPosition(float x, float y) Sets the position of this sprite. |
public final void | setRotation(float angle) Sets the rotational angle of this entity. |
public final void | setScale(float scaleValue) Sets the scaling factor for this sprite. |
public final void | setScale(float scaleX, float scaleY) Sets the scaling factor for this sprite, specifying different values horizontally and
vertically. |
Methods inherited from java.lang.Object
clone
, equals
, finalize
, getClass
, hashCode
, notify
, notifyAll
, toString
, wait
, wait
, wait
Field Detail
alpha |
---|
protected alpha Holds the alpha transparency value for this sprite. |
anim |
---|
protected anim Holds the animation currently applied to this sprite. |
cf |
---|
protected final cf Holds color filter currently applied to this sprite. |
pos |
---|
protected final pos Holds current position of this sprite. |
rotation |
---|
protected rotation Holds the rotational angle. |
scale |
---|
protected final scale Holds scaling factor in both dimensions. |
Constructor Detail
SpriteEntity |
---|
protected SpriteEntity()Called by subclasses to initialize the sprite. |
Method Detail
advance | ||
---|---|---|
public void advance( float elapsedTime ) Advances the animation for this sprite. This method is called by
EntityCollection when the scene is being advanced.Parameters:
Specified By:
|
getAlpha |
---|
public final float getAlpha() Gets the transparency value for this sprite. Specified By:
Returns:
The alpha value for transparency See Also:
|
getAnimation |
---|
public final AnimationHandler getAnimation() Gets the current animation handler assigned to this sprite. Specified By:
Returns:
Animation handler |
getColorFilter |
---|
public final RGB getColorFilter() Gets the color filter for this sprite. Modifying the fields in the returned value affects
the color filter. Specified By:
Returns:
The color filter |
getPosition |
---|
public final Point2D getPosition() Gets the current position of this entity. Specified By:
Returns:
Current 2-dimensional position |
getRotation |
---|
public final float getRotation() Gets the current rotational angle of this entity. Specified By:
Returns:
Rotational angle in degrees |
getScale |
---|
public final Point2D getScale() Gets the 2-dimensional scaling factor for this sprite. Specified By:
Returns:
The scaling factor over horizontal and vertical axes |
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 |
move | ||||
---|---|---|---|---|
public final void move( float amountX, float amountY ) Moves this sprite the given distance. The translation will be relative to this sprite's
current position. Parameters:
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:
|
rotate | ||
---|---|---|
public final void rotate( float angle ) Rotates this sprite the given number of degrees. This rotation will be relative to this
sprite's current rotation angle. Parameters:
Specified By:
|
setAlpha | ||
---|---|---|
public final void setAlpha( float alphaValue ) Sets the transparency value for this sprite. An alpha value of 1 indicates a fully opaque
sprite and a value of 0 is an invisible sprite. Any value in between can be specified to
achieve transparency. Parameters:
Specified By:
|
setAnimation | ||
---|---|---|
public final void setAnimation( AnimationHandler animation ) Sets the animation handler for this sprite. Once set, the animation will be played on this
sprite automatically, until set to null. Parameters:
Specified By:
|
setColorFilter | ||||||
---|---|---|---|---|---|---|
public final void setColorFilter( float r, float g, float b ) Sets the color filter for this sprite. The original colors will be multiplied by this color
when rendering. Parameters:
Specified By:
|
setColorFilter | ||
---|---|---|
public final void setColorFilter( RGB rgb ) Sets the color filter for this sprite. The original colors will be multiplied by this color
when rendering. Parameters:
Specified By:
|
setPosition | ||
---|---|---|
public final void setPosition( Point2D position ) Sets the position of this sprite. This method is guaranteed not to have any performance
benefit over setPosition(float, float) .Parameters:
Specified By:
|
setPosition | ||||
---|---|---|---|---|
public void setPosition( float x, float y ) Sets the position of this sprite. Parameters:
Specified By:
|
setRotation |
---|
public final void setRotation( float angle ) Sets the rotational angle of this entity. Specified By:
|
setScale | ||
---|---|---|
public final void setScale( float scaleValue ) Sets the scaling factor for this sprite. Horizontal and vertical scaling factors will be set
to a single value. Parameters:
Specified By:
|
setScale | ||||
---|---|---|---|---|
public final void setScale( float scaleX, float scaleY ) Sets the scaling factor for this sprite, specifying different values horizontally and
vertically. Parameters:
Specified By:
|