Package com.dkt.graphics.extras
Class GSprite
java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.extras.GSprite
Creates a simple sprite, if you need help creating the pixmaps, you should
probably try out PixmapCreator
- Author:
- Federico Vera <[email protected]>
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAppend a newGPixMapto thisGSprite, this method will skip allGPixMapthat are already in theGSpriteclone()voiddraw(Graphics2D g) Draws the component on the given graphicsbooleandrawGrid()Tells if theGSpritewill draw the inner lines or notvoidfirst()Sets the firstGPixMapas the current one.Retrieves the current bounds of thisGSpriteintRetrieves the current cursor positionintRetrieves the pixel size of theGSpritebooleanisCyclic()Tells if theGSpriteshould behave as a circular list.
The default value istrue.booleanTells if theGSpriteis visibleiterator()voidlast()Sets the lastGPixMapas the current one.booleannext()Passes to the nextGPixMapin 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 onisCyclic().booleanprev()Passes to the previousGPixMapin 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 onisCyclic().booleanRemoves a givenmapfrom the sprite.voidsetCyclic(boolean cyclic) Tells theGSpriteto act as if the list of elements is circular (cyclic), that means that when the lastGPixMapis reached, then it will continue with the first one, and viceversa.
The default value istrue.voidsetDrawGrid(boolean grid) Tells theGSpriteto draw the inner/outer linesvoidsetPixelSize(int px) Sets a new pixel size for all of theGPixMapof thisGSpritevoidsetSkips(int s) voidsetVisible(boolean visible) Tells theGSpriteif it should draw itselfintskips()voidtraslate(int x, int y) Traslates this element on X and YMethods inherited from class com.dkt.graphics.elements.GraphicE
equals, getPaint, getStroke, hashCode, setPaint, setStrokeMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
GSprite
-
GSprite
public GSprite()Creates an empty sprite
-
-
Method Details
-
append
Append a newGPixMapto thisGSprite, this method will skip allGPixMapthat are already in theGSprite- Parameters:
map-GPixMapto add- Throws:
IllegalArgumentException- ifmapisnullInvalidArgumentException- if themapdoesn't have the same size.
-
remove
Removes a givenmapfrom the sprite. This method is most likely to fail, sinceGPixMap.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:
trueif the element was found and removed andfalseotherwise- Throws:
IllegalArgumentException- ifmapisnull
-
getCursor
public int getCursor()Retrieves the current cursor position- Returns:
- cursor position
-
first
public void first()Sets the firstGPixMapas the current one. -
prev
public boolean prev()Passes to the previousGPixMapin 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 onisCyclic().- Returns:
truethe pixmap change andfalseotherwise.- See Also:
-
next
public boolean next()Passes to the nextGPixMapin 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 onisCyclic().- Returns:
truethe pixmap change andfalseotherwise.- See Also:
-
last
public void last()Sets the lastGPixMapas the current one. -
isCyclic
public boolean isCyclic()Tells if theGSpriteshould behave as a circular list.
The default value istrue.- Returns:
trueif theGSpriteis circular, andfalseotherwise.- See Also:
-
setCyclic
public void setCyclic(boolean cyclic) Tells theGSpriteto act as if the list of elements is circular (cyclic), that means that when the lastGPixMapis reached, then it will continue with the first one, and viceversa.
The default value istrue.- Parameters:
cyclic-trueif theGSpriteshould act as circular, andfalseotherwise.- See Also:
-
setSkips
Sets the number of skips, this means how many times should thenext()andprev()should be called in order to actually work
The default value is 1- Parameters:
s- new number of skips- Throws:
InvalidArgumentException- ifsis less than 1
-
skips
public int skips()Retrieves the number of skips that are necessary in order for thenext()andprev()methods to make an actual change.- Returns:
- number of skips
-
setPixelSize
Sets a new pixel size for all of theGPixMapof thisGSprite- Parameters:
px- new pixel size- Throws:
InvalidArgumentException- if thesize <= 0
-
getPixelSize
public int getPixelSize()Retrieves the pixel size of theGSprite- Returns:
- pixel size
-
setDrawGrid
public void setDrawGrid(boolean grid) Tells theGSpriteto draw the inner/outer lines- Parameters:
grid-trueto draw the lines andfalseotherwise
-
drawGrid
public boolean drawGrid()Tells if theGSpritewill draw the inner lines or not- Returns:
trueif theGSpriteis drawing the inner lines andfalseotherwise
-
getBounds
Retrieves the current bounds of thisGSprite- Returns:
- bounds of this GSprite
-
setVisible
public void setVisible(boolean visible) Tells theGSpriteif it should draw itself- Parameters:
visible-trueif theGSpriteshould be drawn andfalseotherwise
-
isVisible
public boolean isVisible()Tells if theGSpriteis visible- Returns:
trueif theGSpriteis visible andfalseotherwise
-
draw
Description copied from class:GraphicEDraws the component on the given graphics -
clone
-
traslate
public void traslate(int x, int y) Description copied from class:GraphicETraslates this element on X and Y -
iterator
-