The Ronin Sprite Engine


Overview

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:


Operation

Sprite engine updates occur in 5 steps: Unfortunately, the obvious optimizations to steps 4 and 5 (like only redrawing changed sprites or only erasing uncovered areas) fail due to our inability to handle transparency manually.  However, the native libraries should be fast enough to make up for it.  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 p, Dimension d ); 
} 

The SpriteCanvas class is the sprite engine.

public class SpriteCanvas extends Canvas 
{ 
    private Image mOffscreenBuffer; 
    private PixelArray mBackdrop; 
    private DoubleLinkedList mSpriteList; // sorted by

    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