Class GSprite

java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.extras.GSprite
All Implemented Interfaces:
Cloneable, Iterable<GPixMap>

public class GSprite extends GraphicE implements Iterable<GPixMap>
Creates a simple sprite, if you need help creating the pixmaps, you should probably try out PixmapCreator
Author:
Federico Vera <[email protected]>
  • Field Summary

    Fields inherited from class com.dkt.graphics.elements.GraphicE

    STROKE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty sprite
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Append a new GPixMap to this GSprite, this method will skip all GPixMap that are already in the GSprite
     
    void
    Draws the component on the given graphics
    boolean
    Tells if the GSprite will draw the inner lines or not
    void
    Sets the first GPixMap as the current one.
    Retrieves the current bounds of this GSprite
    int
    Retrieves the current cursor position
    int
    Retrieves the pixel size of the GSprite
    boolean
    Tells if the GSprite should behave as a circular list.
    The default value is true.
    boolean
    Tells if the GSprite is visible
     
    void
    Sets the last GPixMap as the current one.
    boolean
    Passes to the next GPixMap in the current sprite.
    This method depends on the number of skips set, that is: if skips is 3, then this method must be called 3 times in order to make an actual change, apart from it, it also depends on isCyclic().
    boolean
    Passes to the previous GPixMap in the current sprite.
    This method depends on the number of skips set, that is: if skips is 3, then this method must be called 3 times in order to make an actual change, apart from it, it also depends on isCyclic().
    boolean
    Removes a given map from the sprite.
    void
    setCyclic(boolean cyclic)
    Tells the GSprite to act as if the list of elements is circular (cyclic), that means that when the last GPixMap is reached, then it will continue with the first one, and viceversa.
    The default value is true.
    void
    setDrawGrid(boolean grid)
    Tells the GSprite to draw the inner/outer lines
    void
    setPixelSize(int px)
    Sets a new pixel size for all of the GPixMap of this GSprite
    void
    setSkips(int s)
    Sets the number of skips, this means how many times should the next() and prev() should be called in order to actually work
    The default value is 1
    void
    setVisible(boolean visible)
    Tells the GSprite if it should draw itself
    int
    Retrieves the number of skips that are necessary in order for the next() and prev() methods to make an actual change.
    void
    traslate(int x, int y)
    Traslates this element on X and Y

    Methods inherited from class com.dkt.graphics.elements.GraphicE

    equals, getPaint, getStroke, hashCode, setPaint, setStroke

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • GSprite

      public GSprite(GSprite e)
    • GSprite

      public GSprite()
      Creates an empty sprite
  • Method Details

    • append

      public void append(GPixMap map) throws IllegalArgumentException, InvalidArgumentException
      Append a new GPixMap to this GSprite, this method will skip all GPixMap that are already in the GSprite
      Parameters:
      map - GPixMap to add
      Throws:
      IllegalArgumentException - if map is null
      InvalidArgumentException - if the map doesn't have the same size.
    • remove

      public boolean remove(GPixMap map) throws IllegalArgumentException
      Removes a given map from the sprite. This method is most likely to fail, since GPixMap.equals(java.lang.Object) relies on the pixel size and the grid, and those attributes are mostly certainly changed by the constructor.
      Parameters:
      map - Map to remove
      Returns:
      true if the element was found and removed and false otherwise
      Throws:
      IllegalArgumentException - if map is null
    • getCursor

      public int getCursor()
      Retrieves the current cursor position
      Returns:
      cursor position
    • first

      public void first()
      Sets the first GPixMap as the current one.
    • prev

      public boolean prev()
      Passes to the previous GPixMap in the current sprite.
      This method depends on the number of skips set, that is: if skips is 3, then this method must be called 3 times in order to make an actual change, apart from it, it also depends on isCyclic().
      Returns:
      true the pixmap change and false otherwise.
      See Also:
    • next

      public boolean next()
      Passes to the next GPixMap in the current sprite.
      This method depends on the number of skips set, that is: if skips is 3, then this method must be called 3 times in order to make an actual change, apart from it, it also depends on isCyclic().
      Returns:
      true the pixmap change and false otherwise.
      See Also:
    • last

      public void last()
      Sets the last GPixMap as the current one.
    • isCyclic

      public boolean isCyclic()
      Tells if the GSprite should behave as a circular list.
      The default value is true.
      Returns:
      true if the GSprite is circular, and false otherwise.
      See Also:
    • setCyclic

      public void setCyclic(boolean cyclic)
      Tells the GSprite to act as if the list of elements is circular (cyclic), that means that when the last GPixMap is reached, then it will continue with the first one, and viceversa.
      The default value is true.
      Parameters:
      cyclic - true if the GSprite should act as circular, and false otherwise.
      See Also:
    • setSkips

      public void setSkips(int s) throws InvalidArgumentException
      Sets the number of skips, this means how many times should the next() and prev() should be called in order to actually work
      The default value is 1
      Parameters:
      s - new number of skips
      Throws:
      InvalidArgumentException - if s is less than 1
    • skips

      public int skips()
      Retrieves the number of skips that are necessary in order for the next() and prev() methods to make an actual change.
      Returns:
      number of skips
    • setPixelSize

      public void setPixelSize(int px) throws InvalidArgumentException
      Sets a new pixel size for all of the GPixMap of this GSprite
      Parameters:
      px - new pixel size
      Throws:
      InvalidArgumentException - if the size <= 0
    • getPixelSize

      public int getPixelSize()
      Retrieves the pixel size of the GSprite
      Returns:
      pixel size
    • setDrawGrid

      public void setDrawGrid(boolean grid)
      Tells the GSprite to draw the inner/outer lines
      Parameters:
      grid - true to draw the lines and false otherwise
    • drawGrid

      public boolean drawGrid()
      Tells if the GSprite will draw the inner lines or not
      Returns:
      true if the GSprite is drawing the inner lines and false otherwise
    • getBounds

      public GRectangle getBounds()
      Retrieves the current bounds of this GSprite
      Returns:
      bounds of this GSprite
    • setVisible

      public void setVisible(boolean visible)
      Tells the GSprite if it should draw itself
      Parameters:
      visible - true if the GSprite should be drawn and false otherwise
    • isVisible

      public boolean isVisible()
      Tells if the GSprite is visible
      Returns:
      true if the GSprite is visible and false otherwise
    • draw

      public void draw(Graphics2D g)
      Description copied from class: GraphicE
      Draws the component on the given graphics
      Specified by:
      draw in class GraphicE
      Parameters:
      g - where to draw
    • clone

      public GSprite clone()
      Specified by:
      clone in class GraphicE
    • traslate

      public void traslate(int x, int y)
      Description copied from class: GraphicE
      Traslates this element on X and Y
      Specified by:
      traslate in class GraphicE
      Parameters:
      x - size in px of the horizontal translation
      y - size in px of the vertical translation
    • iterator

      public Iterator<GPixMap> iterator()
      Specified by:
      iterator in interface Iterable<GPixMap>