public class Sprite
extends java.lang.Object
Constructor and Description |
---|
Sprite(Image image)
Creates a Sprite with the same width and height as the specified Image.
|
Sprite(Image image,
int width,
int height)
Creates a Sprite based on the specified Image object,
with the specified width and height.
|
Sprite(int w,
int h)
Creates a Sprite with the specified width and height.
|
Sprite(int cols,
int rows,
int tileWidth,
int tileHeight)
Creates a tiled Sprite with the specified number of rows and columns.
|
Modifier and Type | Method and Description |
---|---|
void |
addFrame(Image image,
int x,
int y)
Adds a frame to the Sprite.
|
void |
addFrames(Image image,
int... locations)
A variant of addFrame() which allows multiple frames from
one Image object to be added to the sprite with one method call.
|
void |
bounceIfCollidesWith(Sprite... _sprite)
This method tests whether this sprite overlaps with the sprite passed in
and bounce if collision occurs.
|
void |
buttonAction(char _action,
int _x,
int _y) |
void |
checkIfCollidesWith(Sprite... _sprite)
Like the other xxxIfCollidesWith() methods, this methods test whether the
two sprites will overlap in the next x and y positions.
|
boolean |
collided(int... sides)
Returns a boolean value of true or false, depending on
whether an collision was detected in the immediately preceeding
xxxIfCollidesWith() call.
|
java.lang.String |
currSequence()
Returns the name of the sprite's current sequence.
|
void |
defineSequence(java.lang.String sequenceName,
int... frameIndices)
Defines, for an animated sprite, a sequence of one or more
animation frames, which can later be cycled through while the sprite is displayed.
|
void |
draw()
Causes the sprite, and any other sprites pinned to this sprite, to be
drawn on the canvas, unless the sprite is hidden.
|
void |
flipHorizontal()
Flips the sprite around a vertical line running through the
center of the sprite.
|
void |
flipVertical()
Flips the sprite around a horizontal line running through the
center of the sprite.
|
void |
font(java.lang.String fontName,
int style,
int size)
Specifies the font to use in subsequent calls to putText() with this Sprite.
|
void |
font(java.lang.String fontName,
int style,
int size,
int r,
int g,
int b)
Specifies the font and font color to use in subsequent calls to putText() with this Sprite.
|
void |
framerate(int d)
Sets a framerate for this sprite; Ucigame will try to change the sprite's
current frame number d times per second, although there is no guarantee
that it will be successful.
|
int |
height()
Returns the sprite's height.
|
void |
hide()
Hides the sprite from view.
|
boolean |
isShown()
Returns true if the sprite is not currently hidden with hide().
|
void |
makeButton(java.lang.String name)
Makes a button with the specified name.
|
void |
motion(double x,
double y)
Sets the x and y motion amount for this sprite.
|
void |
motion(double x,
double y,
int command)
Changes the x and y motion amounts based on the value of command.
|
void |
move()
Moves the sprite by its x and y motion amounts.
|
void |
nextX(double _nextX)
Sets the sprite's next x positions (relative to the upper left hand
corner of the canvas).
|
void |
nextY(double _nextY)
Sets the sprite's next y positions (relative to the upper left hand
corner of the canvas).
|
void |
pauseIfCollidesWith(Sprite... _sprite)
This method tests whether this sprite overlaps with the sprite passed in
and pauses.
|
void |
pin(Sprite pinnedSprite,
int x,
int y)
Pins pinnedSprite on top of current sprite (this),
which means that pinnedSprite will be drawn whenever this.draw() is
performed.
|
void |
play(java.lang.String sequenceName)
Sets the sprite's animation sequence to the series of frames
indicated by sequenceName.
|
void |
play(java.lang.String sequenceName,
int ONCE)
Sets the sprite's animation sequence to the series of frames
indicated by sequenceName.
|
void |
play(java.lang.String sequenceNameRepeat,
int repetitions,
java.lang.String sequenceNameLoop)
Sets the sprite's animation sequence to the series of frames
indicated by sequenceName, and plays that sequence repetitions times.
|
void |
play(java.lang.String sequenceNameRepeat,
int repetitions,
java.lang.String sequenceNameLoop,
int ONCE)
Sets the sprite's animation sequence to the series of frames
indicated by sequenceName, and plays that sequence repetitions times.
|
void |
play(java.lang.String sequenceNameOnce,
java.lang.String sequenceNameLoop)
Sets the sprite's animation sequence to the series of frames
indicated by sequenceName, and plays that sequence one time.
|
void |
play(java.lang.String sequenceNameOnce,
java.lang.String sequenceNameLoop,
int ONCE)
Sets the sprite's animation sequence to the series of frames
indicated by sequenceName, and plays that sequence one time.
|
void |
position(double x,
double y)
Moves the sprite so that its upper left hand corner is at the specified
position, relative to the upper left hand corner of the canvas (or to
the upper left hand corner of its parent, if this sprite is pinned).
|
void |
putText(double D,
double x,
double y)
Draws the specified double D on the sprite, using the sprite's current font.
|
void |
putText(int N,
double x,
double y)
Draws the specified int N on the sprite, using the sprite's current font.
|
void |
putText(java.lang.String string,
double x,
double y)
Draws the specified String on the sprite, using the sprite's current font.
|
void |
restart()
For an animated sprite, sets the next frame to display
(when sprite1.draw() is next called) to frame 0 (the first frame in the sequence).
|
void |
rotate(double degrees)
Rotates the sprite counterclockwise by the number of degrees specified.
|
void |
rotate(double degrees,
double rotCenterX,
double rotCenterY)
Same as the one parameter version of rotate(), except that the center of
rotation is rotCenterX pixels to the right and rotCenterY pixels down from
the upper left
hand corner of the sprite.
|
void |
setTiles(Image gameImage,
int x,
int y,
int... locations)
Takes a frame from gameImage (with an upper left hand corner as
specified by x and y and with width and height as specified in
makeTiledSprite()), and puts that frame into one or more of the sprite's
tiles as specified by the col and row pairs specified by location.
|
void |
setToFrame(int frameNumber)
For an animated sprite, sets the next frame to display
(when sprite1.draw() is next called) to the specified frame in the
current sequence.
|
void |
show()
Shows the sprite; cancels the effect of a call to hide().
|
void |
stopIfCollidesWith(Sprite... _sprite)
This method tests whether this sprite overlaps with the sprite passed in
and stop movement if collision occurs.
|
java.lang.String |
toString()
non-API
|
int |
width()
Returns the sprite's width.
|
double |
x()
Returns the x value of the sprite's upper left hand corner, relative to the
upper left hand corner of the canvas.
|
int |
xPixel()
This method returns the x value of the sprite's upper left hand corner
(relative to the upper left hand corner of the canvas).
|
double |
xspeed()
This methods return the sprite's current x change amounts.
|
double |
y()
Returns the y value of the sprite's upper left hand corner, relative to the
upper left hand corner of the canvas.
|
int |
yPixel()
This method returns the y values of the sprite's upper left hand corner
(relative to the upper left hand corner of the canvas).
|
double |
yspeed()
This methods return the sprite's current y change amounts.
|
public Sprite(Image image)
public Sprite(int cols, int rows, int tileWidth, int tileHeight)
public Sprite(int w, int h)
public Sprite(Image image, int width, int height)
public void addFrame(Image image, int x, int y)
public void addFrames(Image image, int... locations)
public void setTiles(Image gameImage, int x, int y, int... locations)
public void pin(Sprite pinnedSprite, int x, int y)
public void framerate(int d)
public void rotate(double degrees)
public void rotate(double degrees, double rotCenterX, double rotCenterY)
public void flipHorizontal()
public void flipVertical()
public void defineSequence(java.lang.String sequenceName, int... frameIndices)
public java.lang.String currSequence()
public void play(java.lang.String sequenceName)
public void play(java.lang.String sequenceName, int ONCE)
public void play(java.lang.String sequenceNameOnce, java.lang.String sequenceNameLoop)
public void play(java.lang.String sequenceNameOnce, java.lang.String sequenceNameLoop, int ONCE)
public void play(java.lang.String sequenceNameRepeat, int repetitions, java.lang.String sequenceNameLoop)
public void play(java.lang.String sequenceNameRepeat, int repetitions, java.lang.String sequenceNameLoop, int ONCE)
public void restart()
public void setToFrame(int frameNumber)
public void draw()
public void font(java.lang.String fontName, int style, int size)
public void font(java.lang.String fontName, int style, int size, int r, int g, int b)
public void putText(int N, double x, double y)
public void putText(double D, double x, double y)
public void putText(java.lang.String string, double x, double y)
public int width()
public int height()
public void hide()
public void show()
public boolean isShown()
public void position(double x, double y)
public void motion(double x, double y)
public void motion(double x, double y, int command)
public void move()
public double x()
public double y()
public int xPixel()
public int yPixel()
public void nextX(double _nextX)
_nextX
- the next x value for the spritepublic void nextY(double _nextY)
_nextY
- the next y value for the spritepublic double xspeed()
public double yspeed()
public boolean collided(int... sides)
public void makeButton(java.lang.String name)
public final void buttonAction(char _action, int _x, int _y)
public void bounceIfCollidesWith(Sprite... _sprite)
public void stopIfCollidesWith(Sprite... _sprite)
public void checkIfCollidesWith(Sprite... _sprite)
public void pauseIfCollidesWith(Sprite... _sprite)
public final java.lang.String toString()
toString
in class java.lang.Object