gamingtools
Interface RenderListener

All Known Implementing Classes:
FrameBuilder

public interface RenderListener

A class that is interested in generating animation frames implements this interface. For each frame, GraphicsSource invokes updateModel() to update the state of the game, followed by render() to display the state to the offscreen image buffer. init() is invoked prior to frame generation on a different thread than the one for the animation loop. It should be used for loading images and sounds, and for configuration.

See Also:
GraphicsSource

Method Summary
 void init(boolean isPageFlipping, int bufferWidth, int bufferHeight)
          This method is used to load images and sounds, and for configuration.
 void render(Graphics g, boolean isBufferCleared, int bufferIndex)
          Displays the game state to the back buffer.
 void updateModel()
          This method is used to update the state of the game.
 

Method Detail

init

public void init(boolean isPageFlipping,
                 int bufferWidth,
                 int bufferHeight)
This method is used to load images and sounds, and for configuration. It is invoked prior to frame generation on a different thread than the one for the animation loop.

Parameters:
isPageFlipping - Indicates whether the BufferStrategy within GraphicsSource employs page flipping. If true, then even frames and odd frames are drawn to different offscreen buffers. Otherwise, all frames are drawn to the same buffer. This parameter determines how the buffer must be updated to generate the next frame.
bufferWidth - The width of the buffers.
bufferHeight - The height of the bufrers.

updateModel

public void updateModel()
This method is used to update the state of the game. GraphicsSource tries to sustain the apparent frame rate by assuming that the time required to update the game state is significantly less than the time to display it. It will occasionally and typically unnoticeably invoke updateModel() more often than render(), to effectively skips frames.


render

public void render(Graphics g,
                   boolean isBufferCleared,
                   int bufferIndex)
Displays the game state to the back buffer.

Parameters:
g - The graphics context used to draw the animation frame. Do not invoke g.dispose(). Disposal of this graphics context is automatically performed by GraphicsSource.
isBufferCleared - Indicates whether the buffer is in the same state since the last time it was drawn to. Occationally, the buffer may be losted and restored. When this happens, it is effectively erased. If this parameter is true, then the entire buffer needs to be painted. Otherwise, only the portion of the buffer that changes for this frame needs to be updated. Note, after calling GraphicsSource.setRenderListener(), this parameter will be true for the first frame or two depending upon which buffer strategy is employed.
bufferIndex - If page flipping is used, then this parameter will alternate between 0 and 1. Otherwise, it will always be 0.