public class Sprite
extends java.lang.Object
getImage(Sprite.ID, double)
passing in the id of the image they want and a scale factor.
Use caution: getImage(Sprite.ID, double)
is a public static
method, intended for use by the user. getImage(double)
is a private
instance method, used internally.
getImage(Sprite.ID, double)
Modifier and Type | Class and Description |
---|---|
static class |
Sprite.ID
Houses all Sprites' info.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
fname
The path to the source image, relative to the imges/ directory
|
private static int |
frameCounter
The frame number, used to calculate the frame to use in animated sprites.
|
private int |
frameDivider
The number of in-game frames that progress in order to move on to the next frame of this Sprite,
|
private static java.util.HashMap<Sprite.ID,Sprite> |
instances
Contains all Sprite instances.
|
private int |
numTilesHigh
The number of tiles in a single column of the tileset
|
private int |
numTilesWide
The number of tiles in a single row of the tileset
|
private java.awt.image.BufferedImage |
scaled
A scaled version of
source , scaled according to the scale factor scaleFactor |
private java.awt.image.BufferedImage[] |
scaledTiles
A array of tiles, cropped out of
scaled |
private double |
scaleFactor
The scaleFactor used to generate the currently saved scaled image
|
private java.awt.image.BufferedImage |
source
The completely unprocessed source image
|
private int |
worldHeight
The display height of the Sprite, in world coordinates
|
private int |
worldWidth
The display width of the Sprite, in world coordinates
|
Modifier | Constructor and Description |
---|---|
private |
Sprite(java.lang.String fname,
int worldWidth,
int worldHeight,
int numTilesWide,
int numTilesHigh,
int frameDivider)
Creates a Sprite with the specified attributes, not to be called by the user,
|
Modifier and Type | Method and Description |
---|---|
private java.awt.image.BufferedImage |
getImage(double scaleFactor)
Retrieve the correctly scaled image according to the scaleFactor, loading from disk if necessary, scaling if necessary, and tiling if necessary.
|
static java.awt.image.BufferedImage |
getImage(Sprite.ID id,
double scaleFactor)
Retrieve the correctly scaled image for the given id, according to the given scaleFactor, loading from disk if necessary, scaling if necessary, and tiling if necessary.
|
private java.awt.image.BufferedImage |
getRawImage()
Retrieve the unscaled image, loading from disk if necessary.
|
static java.awt.image.BufferedImage |
getRawImage(Sprite.ID id)
Retrieves thet unscaled version of the image.
|
static void |
incrementFrameCounter()
Increment the frame counter used for animated Sprites.
|
private void |
loadSource()
Ensures that the image is loaded from disk.
|
private static Sprite |
makeInstance(Sprite.ID id)
Returns an instance of Sprite for the given Sprite.ID.
|
private void |
scale(double scaleFactor)
Ensures that the image has been scaled according to the specified scale factor.
|
private void |
tile()
Ensures that the image has been tiled into individual frames.
|
private static java.util.HashMap<Sprite.ID,Sprite> instances
private static int frameCounter
private java.lang.String fname
private double scaleFactor
private int worldWidth
private int worldHeight
private int numTilesWide
private int numTilesHigh
private int frameDivider
private java.awt.image.BufferedImage source
private java.awt.image.BufferedImage scaled
source
, scaled according to the scale factor scaleFactor
private java.awt.image.BufferedImage[] scaledTiles
scaled
private Sprite(java.lang.String fname, int worldWidth, int worldHeight, int numTilesWide, int numTilesHigh, int frameDivider)
fname
- The path to the source image, relative to the images/ folder.worldWidth
- The display width of the image, in world coordinates.worldHeight
- The display height of the image, in world coordinates.numTilesWide
- The number of tiles in a single row of the tileset.numTilesHigh
- The number of tiles in a single column of the tileset.frameDivider
- The number of in-game frames that progress in order to move on to the next frame of this Sprite.private static Sprite makeInstance(Sprite.ID id)
id
- The id used to create the imagepublic static java.awt.image.BufferedImage getImage(Sprite.ID id, double scaleFactor)
id
- The sprite id to get the image fromscaleFactor
- The size of the View relative to the Model.public static java.awt.image.BufferedImage getRawImage(Sprite.ID id)
id
- The Sprite ID to get the image frompublic static void incrementFrameCounter()
private void loadSource()
source
.private void scale(double scaleFactor)
scaled
and the scale factor used in scaleFactor
.scaleFactor
- The ratio of the view width to the world widthscaled
,
scaleFactor
private void tile()
scaledTiles
.scaledTiles
private java.awt.image.BufferedImage getImage(double scaleFactor)
scaleFactor
- The ratio of the size of the View to the size of the World, as in getImage(Sprite.ID, double)
getImage(Sprite.ID, double)
private java.awt.image.BufferedImage getRawImage()