|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--gamingtools.FrameBuilder
A class that desires to generate animation frames extends this class. The abstract methods are invoked in the following order:
init() -- Called once prior to frame generation on a
different thread than the one for the animation loop. It is used to load
images and sounds, and for configuration.
updateState() -- Used to update the state of the game.
It will occasionally be invoked more often than the render methods to
maintain the apparent frame rate.
isBackgroundSame() -- Returns true when the
background has not changed. It is used to determine which
renderBackground() method to call.
renderBackground() -- Two overloads, the first draws the
complete background, the second a sub-region of it. If the background has
not changed and the contents of the buffers have not been lost, then
the latter overload is used repeatedly to restore the dirty regions created
by sprite drawing. Otherwise, the former version is used.
renderForeground() -- Draws the sprites and other
foreground graphics. It should use drawSprite() and
markDirtyRegion() appropriately.
GraphicsSource| Nested Class Summary | |
protected class |
FrameBuilder.FrameInfo
Description of an animation frame. |
protected class |
FrameBuilder.Region
Rectangular dirty region. |
| Field Summary | |
protected int |
backgroundNumber
Index that is incremented only if the background changes. |
protected int |
bufferHeight
Height of the buffers. |
protected int |
bufferWidth
Width of the buffers. |
static int |
DEFAULT_MAX_DIRTY_REGIONS
Default maximum dirty regions stored in the history per buffer. |
protected FrameBuilder.FrameInfo[] |
frameInfoHistory
Stored frame descriptions. |
protected int |
historyIndex
Alternates between 0 and 1, or remains at 0. |
protected int |
historySize
Equal to the number of buffers. |
int |
MAX_DIRTY_REGIONS
Maximum number of dirty regions stored in the history per buffer. |
protected FrameBuilder.Region[][] |
regionHistory
Stored dirty regions: [history index][region index] |
| Constructor Summary | |
FrameBuilder()
Constructs this class with a dirty region history size equal to 64. |
|
FrameBuilder(int maxDirtyRegions)
Constructs this class with dirty region history size equal to the specified value. |
|
| Method Summary | |
void |
drawSprite(Graphics g,
Image image,
int x,
int y)
Draws an image at the specified coordinates and marks the region it occupies as dirty. |
abstract void |
init()
This method is used to load images and sounds, and for configuration. |
void |
init(boolean isPageFlipping,
int bufferWidth,
int bufferHeight)
This method is automatically invoked by GraphicsSource. |
abstract boolean |
isBackgroundSame()
Returns true if and only if the background has not changed. |
void |
markDirtyRegion(int x,
int y,
int width,
int height)
Records a dirty region. |
void |
render(Graphics g,
boolean isBufferCleared,
int bufferIndex)
This method is automatically invoked by GraphicsSource. |
abstract void |
renderBackground(Graphics g)
Draws the complete background. |
abstract void |
renderBackground(Graphics g,
int x,
int y,
int width,
int height)
Draws a rectangular sub-region of the background. |
abstract void |
renderForeground(Graphics g)
Draws the sprites and other foreground graphics. |
void |
updateModel()
This method is automatically invoked by GraphicsSource. |
abstract void |
updateState()
This method is used to update the state of the game. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int DEFAULT_MAX_DIRTY_REGIONS
public final int MAX_DIRTY_REGIONS
protected int historySize
protected FrameBuilder.Region[][] regionHistory
[history index][region index]
protected FrameBuilder.FrameInfo[] frameInfoHistory
protected int historyIndex
protected int backgroundNumber
protected int bufferWidth
protected int bufferHeight
| Constructor Detail |
public FrameBuilder(int maxDirtyRegions)
maxDirtyRegions - Maximum number of dirty regions that can be
recorded for each buffer.public FrameBuilder()
| Method Detail |
public final void init(boolean isPageFlipping,
int bufferWidth,
int bufferHeight)
This method is automatically invoked by GraphicsSource. Do
not call it directly.
This method initializes the dirty region history and delegates the
call to the abstract method init().
init in interface RenderListenerisPageFlipping - 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.init()public final void updateModel()
This method is automatically invoked by GraphicsSource. Do
not call it directly.
This method invokes the abstract method updateState()
followed by the abstract method isBackgroundSame().
updateModel in interface RenderListenerupdateState(),
isBackgroundSame()
public final void render(Graphics g,
boolean isBufferCleared,
int bufferIndex)
This method is automatically invoked by GraphicsSource. Do
not call it directly.
This method invokes one of the abstract renderBackground()
methods followed by the abstract renderForeground()
method.
render in interface RenderListenerg - The graphics context used to draw the animation frame. 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.renderBackground(Graphics),
renderBackground(Graphics,int,int,int,int),
renderForeground(Graphics)
public void drawSprite(Graphics g,
Image image,
int x,
int y)
g - A graphics context to the back buffer.image - Sprite to draw.x - Horizontal position of the upper-left corner.y - Vertical position of the upper-left corner.markDirtyRegion(int,int,int,int)
public void markDirtyRegion(int x,
int y,
int width,
int height)
drawBackground().
x - Horizontal position of the upper-left corner.y - Vertical position of the upper-left corner.width - Width of the region.height - Height of the region.drawSprite(Graphics,Image,int,int)public abstract void init()
public abstract void updateState()
public abstract boolean isBackgroundSame()
true if and only if the background has not changed.
It is used to determine which renderBackground() method to
call. This method is invoked as often as updateState(), which
is typically more often than the render methods because of frame skipping.
true when the background has not changed;
false otherwise.public abstract void renderBackground(Graphics g)
g.dispose()
since GraphicsSource already takes care of that.
g - A graphics context to the back buffer.
public abstract void renderBackground(Graphics g,
int x,
int y,
int width,
int height)
g.dispose() since GraphicsSource already
takes care of that. g has a clipping region set to the
dirty region.
g - A graphics context to the back buffer.x - Horizontal position of the upper-left corner.y - Vertical position of the upper-left corner.width - Width of the region.height - Heigh of the region.public abstract void renderForeground(Graphics g)
markDirtyRegion(), which records a dirty region for
restoration in a successive frame, and drawSprite(), which is
a convenience method that invokes g.drawImage() followed by
markDirtyRegion().
g - A graphics context to the back buffer.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||