Artenus 2D Framework
Artenus Reference
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 TypeField 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 TypeConstructor and Description
protected SpriteEntity()
Called by subclasses to initialize the sprite.

Method Summary

Modifier and TypeMethod and Description
public voidadvance(float elapsedTime)
Advances the animation for this sprite.
public final floatgetAlpha()
Gets the transparency value for this sprite.
public final AnimationHandlergetAnimation()
Gets the current animation handler assigned to this sprite.
public final RGBgetColorFilter()
Gets the color filter for this sprite.
public final Point2DgetPosition()
Gets the current position of this entity.
public final floatgetRotation()
Gets the current rotational angle of this entity.
public final Point2DgetScale()
Gets the 2-dimensional scaling factor for this sprite.
public booleanhasBehavior(Behaviors behavior)
Indicates whether this entity has the specified behavior.
public final voidmove(float amountX, float amountY)
Moves this sprite the given distance.
public voidonAttach(Scene scene)
Called when this entity is associated with a scene.
public voidonDetach(Scene scene)
Called when this entity is dissociated with a scene.
public final voidrotate(float angle)
Rotates this sprite the given number of degrees.
public final voidsetAlpha(float alphaValue)
Sets the transparency value for this sprite.
public final voidsetAnimation(AnimationHandler animation)
Sets the animation handler for this sprite.
public final voidsetColorFilter(float r, float g, float b)
Sets the color filter for this sprite.
public final voidsetColorFilter(RGB rgb)
Sets the color filter for this sprite.
public final voidsetPosition(Point2D position)
Sets the position of this sprite.
public voidsetPosition(float x, float y)
Sets the position of this sprite.
public final voidsetRotation(float angle)
Sets the rotational angle of this entity.
public final voidsetScale(float scaleValue)
Sets the scaling factor for this sprite.
public final voidsetScale(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:
elapsedTimeThe elapsed time since the previous frame
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:
amountXThe horizontal translation
amountYThe vertical translation
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:
angleThe angle in degrees to rotate
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:
alphaValueThe alpha value for transparency
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:
animationThe animation handler, or null to remove animation
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:
rThe red multiplier
gThe green multiplier
bThe blue multiplier
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:
rgbThe color multipliers
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:
positionThe new position
Specified By:
setPosition
public void setPosition(
    float x,
    float y
)
Sets the position of this sprite.
Parameters:
xThe x coordinate of the new position
yThe y coordinate of the new position
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:
scaleValueThe scaling factor
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:
scaleXHorizontal scaling factor
scaleYVertical scaling factor
Specified By: