org.jrabbit.standard.game.objects.base
Class BaseSprite

java.lang.Object
  extended by org.jrabbit.standard.game.objects.base.Spatial
      extended by org.jrabbit.standard.game.objects.base.BaseSprite
All Implemented Interfaces:
Renderable, Skin, GLTransform, Colored, Dimensioned, GLGroupTransformed, Located, Rotated, Scaled, ScreenObject, Visible
Direct Known Subclasses:
AnimatedSprite, ImageSprite, Particle, ParticleSprite, Sprite, TextSprite

public abstract class BaseSprite
extends Spatial
implements Visible, Colored, ScreenObject, GLGroupTransformed, Skin

BaseSprite defines the a Sprite object. It extends Spatial, adding various rendering capabilities and controls - namely, a visibility flag, a color, a GLGroupTransform (allowing for dynamic changing of render properties), methods to determine whether or not the Sprite is visible, and a control that determines whether the Sprite is rendered in an absolute screen location or is viewed relative to the active Camera. BaseSprite is abstract, and all extending objects need to define three methods: The methods that detect width and height, and draw(), a method that handles how the object is rendered. It should be noted that draw() is called after the contents of the GLGroupTransform are bound, so it does not need to take scaling/rotation/location etc. into account.

Author:
Chris Molini

Field Summary
protected  Color color
          The Color of the BaseSprite.
protected  GLControlledReset screenCoords
          This determines whether or not the BaseSprite is rendered relative to the active camera, or if it is shown in absolute, screen coordinates.
protected  GLGroupTransform transforms
          The dynamic list of GLTransforms that are applied to this object upon rendering.
protected  boolean visible
          Determines whether or not the BaseSprite is visible.
 
Fields inherited from class org.jrabbit.standard.game.objects.base.Spatial
location, rotation, scalar
 
Constructor Summary
BaseSprite()
          Creates a default BaseSprite.
 
Method Summary
 void bind()
          Delegates the bind() call to the GLGroupTransform contained by this BaseSprite.
 Color color()
          Accesses the Color of the BaseSprite.
abstract  void draw()
          BaseSprite delegates its rendering to this method.
 boolean onscreen()
          Determines if this object is onscreen.
 void release()
          Delegates the release() call to the GLGroupTransform contained by this BaseSprite.
 void render()
          Renders the BaseSprite (as dictated by shouldRender()).
 GLControlledReset screenCoords()
          Accesses the object that controls whether or not the BaseSprite is rendered relative to the active camera or in screen coordinates.
 void setVisible(boolean visible)
          Redefines the visibility flag of the BaseSprite.
protected  boolean shouldRender()
          Determines whether or not the BaseSprite should be rendered.
 GLGroupTransform transforms()
          Accesses the list of GLTransforms used to affect the rendering of this BaseSprite.
 boolean visible()
          Learns whether or not the object is currently visible.
 
Methods inherited from class org.jrabbit.standard.game.objects.base.Spatial
location, rotation, scalar, scaledDiameter, scaledHeight, scaledWidth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jrabbit.base.graphics.types.Dimensioned
height, width
 

Field Detail

visible

protected boolean visible
Determines whether or not the BaseSprite is visible.


color

protected Color color
The Color of the BaseSprite. This is white by default.


screenCoords

protected GLControlledReset screenCoords
This determines whether or not the BaseSprite is rendered relative to the active camera, or if it is shown in absolute, screen coordinates.


transforms

protected GLGroupTransform transforms
The dynamic list of GLTransforms that are applied to this object upon rendering.

Constructor Detail

BaseSprite

public BaseSprite()
Creates a default BaseSprite.

Method Detail

screenCoords

public GLControlledReset screenCoords()
Accesses the object that controls whether or not the BaseSprite is rendered relative to the active camera or in screen coordinates.

Returns:
The GLControlledReset that handles pushing and resetting the OpenGL ModelviewMatrix to control rendering.

color

public Color color()
Accesses the Color of the BaseSprite.

Specified by:
color in interface Colored
Returns:
The Color set before every render.

transforms

public GLGroupTransform transforms()
Accesses the list of GLTransforms used to affect the rendering of this BaseSprite.

Specified by:
transforms in interface GLGroupTransformed
Returns:
The GLGroupTransform that maintains a dynamic list of all GLTransforms used in rendering.

visible

public boolean visible()
Learns whether or not the object is currently visible.

Specified by:
visible in interface Visible
Returns:
True if the object is allowed to be rendered, false if not.

setVisible

public void setVisible(boolean visible)
Redefines the visibility flag of the BaseSprite.

Specified by:
setVisible in interface Visible
Parameters:
visible - Whether or not the object should be visible.

onscreen

public boolean onscreen()
Determines if this object is onscreen. This check is influenced by the GLControlledReset object that handles switching to and from screen/world coordinates; it delegates the call to either the active camera or active WindowController, as necessary. NOTE: For speed reasons (to avoid calculating sine/cosine of the angle), this does not check the BaseSprite's rotation, but instead calculates its radius and uses it in the check. Thus, the current rotation does not affect this method at all.

Specified by:
onscreen in interface ScreenObject
Returns:
True if the object is potentially visible when rendered, false if not.

bind

public void bind()
Delegates the bind() call to the GLGroupTransform contained by this BaseSprite.

Specified by:
bind in interface GLTransform
See Also:
GLGroupTransform.bind()

release

public void release()
Delegates the release() call to the GLGroupTransform contained by this BaseSprite.

Specified by:
release in interface GLTransform
See Also:
GLGroupTransform.release()

shouldRender

protected boolean shouldRender()
Determines whether or not the BaseSprite should be rendered. By default, this returns true only if the BaseSprite is visible and if it is considered onscreen().


draw

public abstract void draw()
BaseSprite delegates its rendering to this method. Extensions of the class must define this method.


render

public void render()
Renders the BaseSprite (as dictated by shouldRender()). To render, the following methods are called, in the indicated order: bind(), draw(), and release().

Specified by:
render in interface Renderable