public class Sprite extends Entity
Modifier and Type | Field and Description |
---|---|
java.util.ArrayList<Action> |
actionList |
double |
angle
angle of rotation of the texture
|
Animation |
animation |
(package private) Rectangle |
boundary
shape used for collision
|
boolean |
flipped
determines whether texture is reversed along the y direction
|
(package private) double |
height
height of sprite
|
boolean |
mirrored
determines whether texture is reversed along the x direction
|
double |
opacity
amount of transparency; value from 0.0 (fully transparent) to 1.0 (fully opaque)
|
Physics |
physics |
(package private) Texture |
texture
image displayed when rendering this sprite
|
boolean |
visible
determines if sprite will be visible
|
(package private) double |
width
width of sprite
|
double |
x
x-coordinate of center of sprite
|
double |
y
y-coordinate of center of sprite
|
Constructor and Description |
---|
Sprite()
initialize default values of sprite properties
|
Modifier and Type | Method and Description |
---|---|
void |
act(double deltaTime)
Run any
Action objects added to this Sprite. |
void |
addAction(Action a)
Add an
Action to this Sprite. |
void |
bounceAgainst(Sprite other)
Simulate this sprite bouncing off other sprite.
|
void |
boundToScreen(double screenWidth,
double screenHeight)
Keep sprite completely within screen bounds
by adjusting position if necessary.
|
(package private) void |
draw(javafx.scene.canvas.GraphicsContext context)
Render this sprite to a canvas using specified parameters
|
(package private) Rectangle |
getBoundary()
Get boundary shape for this sprite, adjusted according to current position.
|
boolean |
isOnScreen(double screenWidth,
double screenHeight)
Check if sprite (boundary rectangle) remains on screen
|
boolean |
isOverlapping(Sprite other)
Check if this sprite is overlapping another sprite.
|
void |
moveAtAngle(double distance,
double angleDegrees)
Move sprite by the specified distance at the specified angle.
|
void |
moveBy(double deltaX,
double deltaY)
Move this sprite by the specified amounts.
|
void |
moveForward(double distance)
Move sprite forward by the specified distance at current angle.
|
void |
preventOverlap(Sprite other)
Prevent this sprite from overlapping another sprite.
|
void |
rotateBy(double deltaAngle)
Rotate sprite by the specified angle.
|
void |
setAnimation(Animation anim)
Set the animation to be used by this Sprite.
|
void |
setPhysics(double accValue,
double maxSpeed,
double decValue)
Initialize physics object and corresponding values.
|
void |
setPosition(double x,
double y)
Set the coordinates of the center of this sprite.
|
void |
setSize(double width,
double height)
Set size to use when for boundary and when drawing this sprite
|
void |
setTexture(Texture tex)
Set the texture to be displayed when rendering this sprite.
|
void |
wrapToScreen(double screenWidth,
double screenHeight)
If sprite moves completely beyond one edge of the screen,
adjust position so that it reappears by opposite edge of the screen.
|
public double x
public double y
Texture texture
double width
double height
public boolean visible
Rectangle boundary
public double angle
public double opacity
public boolean mirrored
public boolean flipped
public Physics physics
public java.util.ArrayList<Action> actionList
public Animation animation
public void setPosition(double x, double y)
x
- x-coordinate of center of spritey
- y-coordinate of center of spritepublic void moveBy(double deltaX, double deltaY)
deltaX
- amount to move sprite along x directiondeltaY
- amount to move sprite along y directionpublic void setTexture(Texture tex)
tex
- texture to use for this spritepublic void setSize(double width, double height)
width
- width of spriteheight
- height of spritevoid draw(javafx.scene.canvas.GraphicsContext context)
Rectangle getBoundary()
public boolean isOverlapping(Sprite other)
other
- sprite to check for overlap withpublic void preventOverlap(Sprite other)
other
- sprite to prevent overlap withpublic void rotateBy(double deltaAngle)
deltaAngle
- the angle (in degrees) to rotate this spritepublic void moveAtAngle(double distance, double angleDegrees)
distance
- the distance to move this spriteangleDegrees
- the angle (in degrees) along which to move this spritepublic void moveForward(double distance)
distance
- the distance to move this spritepublic void boundToScreen(double screenWidth, double screenHeight)
screenWidth
- width of screenscreenHeight
- height of screenpublic void wrapToScreen(double screenWidth, double screenHeight)
screenWidth
- width of screenscreenHeight
- height of screenpublic boolean isOnScreen(double screenWidth, double screenHeight)
screenWidth
- width of screenscreenHeight
- height of screenpublic void setPhysics(double accValue, double maxSpeed, double decValue)
accValue
- acceleration valuemaxSpeed
- maximum speeddecValue
- deceleration valuepublic void bounceAgainst(Sprite other)
isOverlapping(Sprite)
.
Requires physics
object to be initialized.other
- Sprite acting as solid surface to bounce againstpublic void setAnimation(Animation anim)
anim
- Animation to be used by this Spritepublic void addAction(Action a)
Action
to this Sprite. Actions are automatically run.a
- action to add to this spritepublic void act(double deltaTime)
Action
objects added to this Sprite.
Actions are run in parallel (except for those created with ActionFactory.sequence(Action...)
and removed from the Sprite when they are finished.