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 status
    Sprite​(float width, float height, java.lang.String src)
    Create a new image Sprite
    Sprite​(float width, float height, javafx.scene.paint.Color color)
    Create a new color Sprite with specified dimensions and color
    Sprite​(Sprite sprite)
    Copy constructor for Sprites
  • Method Summary

    Modifier and Type Method Description
    boolean canLoop()
    Check if the Sprite can loop animation
    boolean equals​(java.lang.Object o)
    Check if two Sprites are similar to each other
    float getDimensions​(Axis axis)
    Get the dimensions of the Sprite for a specific Axis
    int getFrame()
    Get the current frame of the animation
    float getFramerate()
    Get the framerate of the Sprite
    float getHeight()
    Get the height of the Sprite in grid units
    javafx.scene.image.Image getImage()
    Get the Sprite Image
    float getRotation()
    Get the rotation of the Sprite
    float getWidth()
    Get the width of the Sprite in grid units
    boolean isPaused()
    Check if the animation is paused
    Sprite nextFrame()
    Set the current frame to the next frame
    Sprite previousFrame()
    Set the current frame to the previous frame
    Sprite setDimensions​(Axis axis, float dimension)
    Set the dimensions of the Sprite for a specific Axis
    Sprite setDimensions​(Vector dimensions)
    Set the dimensions of the Sprite
    Sprite setFrame​(int frame)
    Set the current frame in the animation
    Sprite setFramerate​(float framerate)
    Set the framerate for the Sprite
    Sprite setHeight​(float height)
    Set the height of the Sprite
    Sprite setLoop​(boolean loop)
    Set the Sprite animation to loop or not
    Sprite setPaused​(boolean paused)
    Set the animation to be paused
    Sprite setRotation​(float rotation)
    Set the rotation of the Sprite
    Sprite setWidth​(float width)
    Set the width of the Sprite
    void update​(float deltaTime)
    Set the current frame to the next available frame based on elapsed time
    This is usually called by the renderer

    Methods 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.FileNotFoundException
      Create a new image Sprite
      Parameters:
      width - Sprite width in grid units
      height - Sprite height in grid units
      src - 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 units
      height - Sprite height in grid units
      color - Sprite Color
    • Sprite

      public Sprite​(float width, float height, float frameRate, boolean loop, java.lang.String... src) throws java.io.FileNotFoundException
      Create 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 Sprite
      frameRate - Frames per second of the Sprite
      width - Sprite width in grid units
      height - Sprite height in grid units
      loop - True to allow Sprite to loop
      Throws:
      java.io.FileNotFoundException
    • Sprite

      public Sprite​(Sprite 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

      public Sprite setDimensions​(Vector dimensions)
      Set the dimensions of the Sprite
      Parameters:
      dimensions - 2D Vector for dimensions
      Returns:
      This Sprite
    • setDimensions

      public Sprite setDimensions​(Axis axis, float dimension)
      Set the dimensions of the Sprite for a specific Axis
      Parameters:
      axis - Axis to set dimension for
      dimension - Dimension in grid units
      Returns:
      This Box
    • getDimensions

      public float getDimensions​(Axis axis)
      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

      public Sprite setWidth​(float width)
      Set the width of the Sprite
      Parameters:
      width - New width in grid units
      Returns:
      This Sprite
    • setHeight

      public Sprite setHeight​(float height)
      Set the height of the Sprite
      Parameters:
      height - New height in grid units
      Returns:
      This Sprite
    • setRotation

      public Sprite setRotation​(float rotation)
      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

      public Sprite setFramerate​(float framerate)
      Set the framerate for the Sprite
      Parameters:
      framerate - New framerate
      Returns:
      This Sprite
    • setLoop

      public Sprite setLoop​(boolean loop)
      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

      public Sprite setPaused​(boolean paused)
      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

      public Sprite nextFrame()
      Set the current frame to the next frame
      Returns:
      This Sprite
    • previousFrame

      public 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

      public Sprite setFrame​(int frame)
      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 class java.lang.Object
      Parameters:
      o - Sprite to check
      Returns:
      True if the two Sprites are equal