Package games.stendhal.client.sprite
Class ImageSprite
java.lang.Object
games.stendhal.client.sprite.ImageSprite
- All Implemented Interfaces:
Sprite
- Direct Known Subclasses:
TextSprite
A sprite to be displayed on the screen. Note that a sprite contains no state
information, i.e. its just the image and not the location. This allows us to
use a single sprite in lots of different places without having to store
multiple copies of the image.
- Author:
- Kevin Glass
-
Constructor Summary
ConstructorsConstructorDescriptionImageSprite(Sprite sprite) Create an image sprite from another sprite.ImageSprite(Image image) Create a new sprite based on an image.ImageSprite(Image image, Object reference) Create a new sprite based on an image. -
Method Summary
Modifier and TypeMethodDescriptioncreateRegion(int x, int y, int width, int height, Object ref) Create a sub-region of this sprite.voidDraw the sprite onto the graphics context provided.voidDraws the image.getFrame(int xIndex, int yIndex) Retrieves a single frame from the image.protected static GraphicsConfigurationgetGC()Get the graphics context of the underlying image.intGet the height of the drawn sprite.getImage()Retrieves the java.awt.Image instance.Get the sprite reference.intgetWidth()Get the width of the drawn sprite.booleanCheck whether the sprite won't change between draws.
-
Constructor Details
-
ImageSprite
Create a new sprite based on an image.- Parameters:
image- The image that is this sprite
-
ImageSprite
Create a new sprite based on an image.- Parameters:
image- The image that is this sprite.reference- The sprite reference, or null.
-
ImageSprite
Create an image sprite from another sprite.- Parameters:
sprite- The source sprite.
-
-
Method Details
-
getGC
-
getGraphics
Get the graphics context of the underlying image.- Returns:
- The graphics context.
-
createRegion
Create a sub-region of this sprite. NOTE: This does not use caching.- Specified by:
createRegionin interfaceSprite- Parameters:
x- The starting X coordinate.y- The starting Y coordinate.width- The region width.height- The region height.ref- The sprite reference.- Returns:
- A new sprite.
-
draw
Draw the sprite onto the graphics context provided. -
draw
Draws the image. -
getHeight
public int getHeight()Get the height of the drawn sprite. -
getReference
Get the sprite reference. This identifier is an externally opaque object that implements equals() and hashCode() to uniquely/repeatably reference a keyed sprite.- Specified by:
getReferencein interfaceSprite- Returns:
- The reference identifier, or
nullif not referencable.
-
getWidth
public int getWidth()Get the width of the drawn sprite. -
isConstant
public boolean isConstant()Description copied from interface:SpriteCheck whether the sprite won't change between draws.- Specified by:
isConstantin interfaceSprite- Returns:
trueif different draws of the sprite always have the same result.
-
getFrame
Retrieves a single frame from the image.- Parameters:
xIndex- Horizontal index.yIndex- Vertical index.- Returns:
- Cropped Sprite.
-
getImage
Retrieves the java.awt.Image instance.
-