Class Sprite
java.lang.Object
xyz.jeremynoesen.pseudo3d.core.graphics.Sprite
public class Sprite
extends java.lang.Object
Sprites to be rendered in game
-
Constructor Summary
Constructors Constructor Description Sprite(float width, float height, float frameRate, boolean loop, java.lang.String... src)
Create a new animated Sprite from a list of images and specified frame rate, width, height, and loop statusSprite(float width, float height, java.lang.String src)
Create a new image SpriteSprite(float width, float height, javafx.scene.paint.Color color)
Create a new color Sprite with specified dimensions and colorSprite(Sprite sprite)
Copy constructor for Sprites -
Method Summary
Modifier and Type Method Description boolean
canLoop()
Check if the Sprite can loop animationboolean
equals(java.lang.Object o)
Check if two Sprites are similar to each otherfloat
getDimensions(Axis axis)
Get the dimensions of the Sprite for a specific Axisint
getFrame()
Get the current frame of the animationfloat
getFramerate()
Get the framerate of the Spritefloat
getHeight()
Get the height of the Sprite in grid unitsjavafx.scene.image.Image
getImage()
Get the Sprite Imagefloat
getRotation()
Get the rotation of the Spritefloat
getWidth()
Get the width of the Sprite in grid unitsboolean
isPaused()
Check if the animation is pausedSprite
nextFrame()
Set the current frame to the next frameSprite
previousFrame()
Set the current frame to the previous frameSprite
setDimensions(Axis axis, float dimension)
Set the dimensions of the Sprite for a specific AxisSprite
setDimensions(Vector dimensions)
Set the dimensions of the SpriteSprite
setFrame(int frame)
Set the current frame in the animationSprite
setFramerate(float framerate)
Set the framerate for the SpriteSprite
setHeight(float height)
Set the height of the SpriteSprite
setLoop(boolean loop)
Set the Sprite animation to loop or notSprite
setPaused(boolean paused)
Set the animation to be pausedSprite
setRotation(float rotation)
Set the rotation of the SpriteSprite
setWidth(float width)
Set the width of the Spritevoid
update(float deltaTime)
Set the current frame to the next available frame based on elapsed time
This is usually called by the rendererMethods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Sprite
public Sprite(float width, float height, java.lang.String src) throws java.io.FileNotFoundExceptionCreate a new image Sprite- Parameters:
width
- Sprite width in grid unitsheight
- Sprite height in grid unitssrc
- Path to image to use for Sprite- Throws:
java.io.FileNotFoundException
-
Sprite
public Sprite(float width, float height, javafx.scene.paint.Color color)Create a new color Sprite with specified dimensions and color- Parameters:
width
- Sprite width in grid unitsheight
- Sprite height in grid unitscolor
- Sprite Color
-
Sprite
public Sprite(float width, float height, float frameRate, boolean loop, java.lang.String... src) throws java.io.FileNotFoundExceptionCreate a new animated Sprite from a list of images and specified frame rate, width, height, and loop status- Parameters:
src
- Path to all images of the animated SpriteframeRate
- Frames per second of the Spritewidth
- Sprite width in grid unitsheight
- Sprite height in grid unitsloop
- True to allow Sprite to loop- Throws:
java.io.FileNotFoundException
-
Sprite
Copy constructor for Sprites- Parameters:
sprite
- Sprite to copy
-
-
Method Details
-
getImage
public javafx.scene.image.Image getImage()Get the Sprite Image- Returns:
- Sprite Image
-
setDimensions
Set the dimensions of the Sprite- Parameters:
dimensions
- 2D Vector for dimensions- Returns:
- This Sprite
-
setDimensions
Set the dimensions of the Sprite for a specific Axis- Parameters:
axis
- Axis to set dimension fordimension
- Dimension in grid units- Returns:
- This Box
-
getDimensions
Get the dimensions of the Sprite for a specific Axis- Parameters:
axis
- Axis to get dimension for- Returns:
- Dimension of the specified Axis
-
getWidth
public float getWidth()Get the width of the Sprite in grid units- Returns:
- Width of the Sprite
-
getHeight
public float getHeight()Get the height of the Sprite in grid units- Returns:
- Height of the Sprite
-
setWidth
Set the width of the Sprite- Parameters:
width
- New width in grid units- Returns:
- This Sprite
-
setHeight
Set the height of the Sprite- Parameters:
height
- New height in grid units- Returns:
- This Sprite
-
setRotation
Set the rotation of the Sprite- Parameters:
rotation
- Rotation in degrees counter-clock-wise- Returns:
- This Sprite
-
getRotation
public float getRotation()Get the rotation of the Sprite- Returns:
- Rotation in degrees counter-clock-wise
-
getFramerate
public float getFramerate()Get the framerate of the Sprite- Returns:
- Animation framerate
-
setFramerate
Set the framerate for the Sprite- Parameters:
framerate
- New framerate- Returns:
- This Sprite
-
setLoop
Set the Sprite animation to loop or not- Parameters:
loop
- True to allow animation loop- Returns:
- This Sprite
-
canLoop
public boolean canLoop()Check if the Sprite can loop animation- Returns:
- True if the animation can loop
-
setPaused
Set the animation to be paused- Parameters:
paused
- True to pause the animation- Returns:
- This Sprite
-
isPaused
public boolean isPaused()Check if the animation is paused- Returns:
- True if paused
-
update
public void update(float deltaTime)Set the current frame to the next available frame based on elapsed time
This is usually called by the renderer- Parameters:
deltaTime
- Time elapsed for the render frame
-
nextFrame
Set the current frame to the next frame- Returns:
- This Sprite
-
previousFrame
Set the current frame to the previous frame- Returns:
- This Sprite
-
getFrame
public int getFrame()Get the current frame of the animation- Returns:
- Current frame of the animation
-
setFrame
Set the current frame in the animation- Parameters:
frame
- Frame number- Returns:
- This Sprite
-
equals
public boolean equals(java.lang.Object o)Check if two Sprites are similar to each other- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- Sprite to check- Returns:
- True if the two Sprites are equal
-