Genuts API

com.genuts.gameui
Class SpriteDisplayManager

java.lang.Object
  extended bycom.genuts.gameui.SpriteDisplayManager
All Implemented Interfaces:
DisplayManager

public class SpriteDisplayManager
extends java.lang.Object
implements DisplayManager

This display manager draws efficiently sprites in the playfield.

The display of the playfield is divided into cells, and only needed cells are redrawn when sprites move.

To be more efficient, this display manager redraws the whole playfield background at the first call, then for forthcoming calls, it redraws only changed parts of the background. Therefore, in paintPlayField(Graphics), you have to check the current clip of the graphics context.

See Also:
PlayField.paintPlayField(Graphics)

Constructor Summary
SpriteDisplayManager(int step)
          Initializes this display manager with a display step.
 
Method Summary
 void addSprite(Sprite sprite)
          Adds a sprite in the display list of this display manager.
 void drawDebug(java.awt.Graphics g)
          Draws debug informations for this display manager.
 int getDisplayStep()
          Returns the display step check of this display manager.
 PlayField getPlayfield()
          Returns the playfield associated with this display manager.
 void invalidateSprite(Sprite sprite)
          Performs actions when a sprite is invalidate.
 void paint(java.awt.Graphics g)
          Displays all visible elements of the playfield.
 void playfieldSizeChanged()
          Informs that the size of the playfield has changed.
 void removeSprite(Sprite sprite)
          Removes a sprite from the display list of this display manager.
protected  void repaintCell(int x, int y)
          Repaints a cell and all sprites contained.
 void reset()
          Resets cache datas for this CollisionManager.
 void setDisplayStep(int step)
          Sets the display step check of this display manager.
 void setPlayfield(PlayField playfield)
          Sets the playfield associated with this display manager.
 void validateSprite(Sprite sprite)
          Performs actions when a sprite is validate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpriteDisplayManager

public SpriteDisplayManager(int step)
Initializes this display manager with a display step.

More the step is small, less sprites will be painted, but more steps will be needed to paint the playfield.

Parameters:
step - Step for display.
Method Detail

getDisplayStep

public int getDisplayStep()
Returns the display step check of this display manager.
More the step is small, less sprites will be painted, but more steps will be needed to paint the playfield.

Returns:
the display step of this display manager.

setDisplayStep

public void setDisplayStep(int step)
Sets the display step check of this display manager.

More the step is small, less sprites will be painted, but more steps will be needed to paint the playfield.

Parameters:
step - The display step for this display manager.

getPlayfield

public PlayField getPlayfield()
Description copied from interface: DisplayManager
Returns the playfield associated with this display manager.

Specified by:
getPlayfield in interface DisplayManager
Returns:
The playfield associated with this display manager.

setPlayfield

public void setPlayfield(PlayField playfield)
Description copied from interface: DisplayManager
Sets the playfield associated with this display manager.

Specified by:
setPlayfield in interface DisplayManager
Parameters:
playfield - The playfield associated with this display manager.

playfieldSizeChanged

public void playfieldSizeChanged()
Informs that the size of the playfield has changed.

Be careful with sprites which are out the new size of the playfield, they are simply ignored.

Specified by:
playfieldSizeChanged in interface DisplayManager

reset

public void reset()
Description copied from interface: DisplayManager
Resets cache datas for this CollisionManager.

Specified by:
reset in interface DisplayManager

addSprite

public void addSprite(Sprite sprite)
Description copied from interface: DisplayManager
Adds a sprite in the display list of this display manager.

Generally, this is called by the playfield when a new sprite is added.

Specified by:
addSprite in interface DisplayManager
Parameters:
sprite - Sprite to add

removeSprite

public void removeSprite(Sprite sprite)
Description copied from interface: DisplayManager
Removes a sprite from the display list of this display manager.

Generally, this is called by the playfield when a sprite is removed.

Specified by:
removeSprite in interface DisplayManager
Parameters:
sprite - Sprite to remove

invalidateSprite

public void invalidateSprite(Sprite sprite)
Description copied from interface: DisplayManager
Performs actions when a sprite is invalidate.

Generally, this is called by a sprite when Sprite.invalidate() is called.

Specified by:
invalidateSprite in interface DisplayManager
Parameters:
sprite - Sprite to invalidate.
See Also:
Sprite.invalidate()

validateSprite

public void validateSprite(Sprite sprite)
Description copied from interface: DisplayManager
Performs actions when a sprite is validate.

Generally, this is called by a sprite when Sprite.validate() is called.

Specified by:
validateSprite in interface DisplayManager
Parameters:
sprite - Sprite to validate.
See Also:
Sprite.validate()

repaintCell

protected void repaintCell(int x,
                           int y)
Repaints a cell and all sprites contained.

If a sprite is in several sprites, all of them are repainted recursivelly.

Parameters:
x - X coodinate of the cell to repaint
y - Y coodinate of the cell to repaint

paint

public void paint(java.awt.Graphics g)
Displays all visible elements of the playfield.

For the playfield, calls the method paintPlayField(Graphics).
For each sprite, calls the method paint(Graphics).

Specified by:
paint in interface DisplayManager
Parameters:
g - The graphics context to use for painting.
See Also:
PlayField.paintPlayField(Graphics), Sprite.paint(Graphics)

drawDebug

public void drawDebug(java.awt.Graphics g)
Description copied from interface: DisplayManager
Draws debug informations for this display manager.

Specified by:
drawDebug in interface DisplayManager
Parameters:
g - The graphics context to use for painting.

Genuts API

Genuts API