|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.gatech.cs2335.lemmings.graphics.TileSet
The tileset class simplifies loading bitmap files that contain several tiles. It is a fairly flexible class, but it does impose certain restrictions on the way the file is organized. First of all, there needs to be a set of control pixels in the upper-right corner of the image. The control pixels start at the coordinate (width-1, 0) and go down from there in the following order: transparency pixel, empty-region pixel, outside anchor pixel, used-region pixel, inside anchor pixel; five in all. The transparency pixel is used for color-keying, and all the pixels of that color in the image will be made transparent. The outside and inside anchor pixels do the same thing currently, and are used to denote the image anchor. When the tile is blitted using the putTile method, the anchor has the coordinates passed in to the method, and the rest of the image is drawn relatively to it. In other words, suppose we blit to rectangular tiles using the same target coordinates. One of the tiles has its anchor in the top-left corner, and the other - in the center. Then the center of the latter tile will coincide with the top-left corner of the former tile. The empty-region and used-region pixels are used to denote where the useful areas of the tile are, and which ones can be discarded. The reason for that is that the tiles in the tileset file have to be arranged in a table. In other words, all tiles in one column have to be the same width, and all the tiles in one row have to be the same height. That is not to say, however, that the width and the height have to be the equal, or that the tiles in different rows have to have the same height, and in different columns - the same width. Suppose a game has only two tiles. We can arrange them in a column. One of the tiles is square, and the other - a very thin rectangle. Then, we could mark the whole first tile as used, and for the second tile - only the space that is actually used up. Since we arranged the tiles in a column, the widths of the tiles have to be the same. However, we can mark the unused areas of the thin tile with the unused-area pixel color, and they will be discarded when blitting.
Revision History:
v1.0 (Mar. 11, 2004) - Created the TileSet class
| Nested Class Summary | |
protected class |
TileSet.FrameInformation
Information structure for one tile in the tileset. |
| Field Summary | |
protected static boolean |
DEBUG
Show debug output? |
protected static boolean |
VERBOSE
Show lots of debug output? |
| Constructor Summary | |
TileSet()
Creates a new TileSet instance. |
|
| Method Summary | |
void |
drawTile(java.awt.Graphics destination,
java.awt.Point coordinates,
int tileNum)
Puts the tile with the specified number onto the graphics context passed in at the specified coordinates. |
protected int |
findFirstOccurrence(int lowBound,
int highBound,
int coordinate,
java.awt.Color c1,
java.awt.Color c2,
boolean vertical)
Finds the coordinate of the first occurrence of one of the test colors. |
protected int |
findLastOccurrence(int lowBound,
int highBound,
int coordinate,
java.awt.Color c1,
java.awt.Color c2,
boolean vertical)
Finds the coordinate of the last occurrence of one of the test colors. |
java.awt.Dimension |
getDimension(int tileNum)
Returns the dimensions of the tile with the specified id. |
java.awt.Rectangle |
getExtent(int tileNum)
Returns the extent of the tile with the specified id. |
java.lang.String |
getFileName()
Returns the name of the file containing the tileset in a string. |
protected TileSet.FrameInformation[] |
getFrameList()
Describe getFrameList method here. |
protected java.awt.image.BufferedImage |
getFramesetImage()
Describe getFramesetImage method here. |
java.awt.image.BufferedImage |
getImage()
Returns the image on which the tileset resides. |
java.awt.Dimension |
getLargestDimension()
Returns the dimensions of the largest tile in the tileset. |
int |
getTileCount()
Returns the number of tiles in the tileset. |
boolean |
loadTileset(java.lang.String name)
Loads the tileset from a file. |
boolean |
reloadTileset()
If the surface was lost, reloads it, but does not reparse the file. |
protected boolean |
specialLoad()
Describe specialLoad method here. |
boolean |
unloadTileset()
Performs all the necessary clean-up operations. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected static final boolean DEBUG
protected static final boolean VERBOSE
| Constructor Detail |
public TileSet()
TileSet instance.
| Method Detail |
public boolean loadTileset(java.lang.String name)
name - a String value
boolean valueprotected boolean specialLoad()
specialLoad method here.
boolean valueprotected TileSet.FrameInformation[] getFrameList()
getFrameList method here.
FrameInformation[] valueprotected java.awt.image.BufferedImage getFramesetImage()
getFramesetImage method here.
BufferedImage value
protected int findFirstOccurrence(int lowBound,
int highBound,
int coordinate,
java.awt.Color c1,
java.awt.Color c2,
boolean vertical)
lowBound - an int valuehighBound - an int valuecoordinate - an int valuec1 - a Color valuec2 - a Color valuevertical - a boolean value
int value
protected int findLastOccurrence(int lowBound,
int highBound,
int coordinate,
java.awt.Color c1,
java.awt.Color c2,
boolean vertical)
lowBound - an int valuehighBound - an int valuecoordinate - an int valuec1 - a Color valuec2 - a Color valuevertical - a boolean value
int valuepublic boolean reloadTileset()
boolean valuepublic boolean unloadTileset()
boolean valuepublic int getTileCount()
int valuepublic java.awt.image.BufferedImage getImage()
BufferedImage valuepublic java.lang.String getFileName()
String valuepublic java.awt.Dimension getLargestDimension()
Dimension valuepublic java.awt.Dimension getDimension(int tileNum)
tileNum - an int value
Dimension valuepublic java.awt.Rectangle getExtent(int tileNum)
tileNum - an int value
Rectangle value
public void drawTile(java.awt.Graphics destination,
java.awt.Point coordinates,
int tileNum)
destination - the context to which we want to draw the tile.coordinates - the coordinates at which we want to draw the tile.tileNum - the number of the tile we want to draw. The tiles
will be numbered automatically, from left to right, from top to
bottom, when the image file is parsed.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||