|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectSprite
public class Sprite
A class to represent a software sprite. A Sprite has a position, velocity (in terms of steps), an image, and can be deactivated. The sprite's image is managed with an ImagesLoader object, and an ImagesPlayer object for looping. The images stored until the image 'name' can be looped through by calling loopImage(), which uses an ImagesPlayer object.
Constructor Summary | |
---|---|
Sprite(int x,
int y,
int panelWidth,
int panelHeight,
ImagesLoader imsLd,
String name)
Sprite constructor. |
Method Summary | |
---|---|
void |
drawSprite(Graphics g)
Draw this Sprite at its current location if it is active. |
int |
getHeight()
The height of the Sprite's image. |
BufferedImage |
getImage()
Get this Sprite's image. |
int |
getPHeight()
The height of the Sprite's enclosing panel. |
int |
getPWidth()
The width of the Sprite's enclosing panel. |
Rectangle |
getRectangle()
Get the bounding Rectangle for this Sprite. |
int |
getWidth()
The width of the Sprite's image. |
int |
getXPosn()
Get x location. |
int |
getXStep()
Get x velocity. |
int |
getYPosn()
Get y location. |
int |
getYStep()
Get y velocity. |
boolean |
isActive()
Check if this Sprite is active. |
void |
loopImage(int animPeriod,
double seqDuration)
Switch on loop playing. |
void |
setActive(boolean a)
Set this Sprite's active status. |
void |
setImage(String name)
Change the image for this Sprite. |
void |
setPosition(int x,
int y)
Set the location of this Sprite. |
void |
setStep(int dx,
int dy)
Change this Sprite's x and y velocity. |
void |
stopLooping()
If looping, stop. |
void |
translate(int xDist,
int yDist)
Change the location of this Sprite. |
void |
updateSprite()
If this Sprite is active the x velocity and y velocity are applied to the x location and y location. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Sprite(int x, int y, int panelWidth, int panelHeight, ImagesLoader imsLd, String name)
x
- x location for upper left corner of spritey
- y loaction for upper left corner of spritepanelWidth
- width of panel that contaisn spritepanelHeight
- height of panel that contains spriteimsLd
- object to load image file for spritename
- name of file that contains sprite imageMethod Detail |
---|
public void setImage(String name)
name
- Name of the file that contains the image.
Do not include the file extension.public void loopImage(int animPeriod, double seqDuration)
animPeriod
- The total time for plaing the loop in seconds.seqDuration
- The update interval for the enclosing
panel in milliseconds.public void stopLooping()
public int getWidth()
public int getHeight()
public int getPWidth()
public int getPHeight()
public boolean isActive()
public void setActive(boolean a)
new
- value for activepublic void setPosition(int x, int y)
x
- the new x for the upper left corner of this Spritey
- the new y for the upper left corner of this Spritepublic void translate(int xDist, int yDist)
xDist
- amount to add to this Sprite's x locationyDist
- amount to add to this Sprite's y locationpublic int getXPosn()
public int getYPosn()
public void setStep(int dx, int dy)
dx
- The new x velocity for this Sprite in pixels per frame.dy
- The new y velocity for this Sprite in pixels per frame.public int getXStep()
public int getYStep()
public Rectangle getRectangle()
public void updateSprite()
public void drawSprite(Graphics g)
g
- The graphics object that is used to draw this Sprite.public BufferedImage getImage()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |