The Ronin Sprite Engine


The sprite engine display is a canvas that represents a virtual rectangular window into a 2D plane.  The sprite engine is responsible for maintaining a list of sprites, clipping them against the view window, and displaying them correctly.  The sprite engine uses a hybrid dirty rectangle technique that takes advantage of Java's features while avoiding its pitfalls. In particular, the following considerations are made:


For single buffering (no offscreen buffer) an update requires the following steps: For double buffering there are a few changes. The sprite engine does not worry about time or motion; it simply draws the sprites where they desire to be drawn.  It is up to the user of the sprite engine to place the sprites and then request the sprite engine to update.  This will make it flexible for a variety of tasks.

Classes and Interfaces

Sprites are abstract so that Ronin characters can be sprites with custom positioning and Z ordering.

public interface Sprite 
    public int GetX(); 
    public int GetY(); 
    public int GetZ(); 
    public Image GetImage(); // the image holds the width and height 

The PixelArray interface is implemented to provide a tiled (or otherwise) backdrop for the sprite engine.

public interface PixelArray 

    public void CopyOut( Image aImage, Point aSrc, Point aDest, Dimension d ); 
    public void CopyOut( Canvas aCanvas, Point aSrc, Point aDest, Dimension d );

The SpriteCanvas class is the sprite engine.

public class SpriteCanvas extends Canvas 
    private Image mOffscreenBuffer; 
    private PixelArray mBackdrop; 
    private LinkedList mSpriteList;
    private LinkedList mDirtyRectangleList;

    public SpriteCanvas( PixelArray aBackdrop, Dimension aSize ); 
    public void AddSprite( Sprite s ); 
    public void RemoveSprite( Sprite s ); 
    public void Update(); 
    public void SetPosition( Point p ); // allows the virtual window to be moved 

Using the Sprite Engine for Ronin Battle Visualization

The sprite engine is meant to be of general use but also easily usable for visualizing Ronin battles.  The following tasks must be performed by the Ronin battle visualization unit between sprite updates:

Technical Notes