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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Append a newGPixMap
to thisGSprite
, this method will skip allGPixMap
that are already in theGSprite
clone()
void
draw
(Graphics2D g) Draws the component on the given graphicsboolean
drawGrid()
Tells if theGSprite
will draw the inner lines or notvoid
first()
Sets the firstGPixMap
as the current one.Retrieves the current bounds of thisGSprite
int
Retrieves the current cursor positionint
Retrieves the pixel size of theGSprite
boolean
isCyclic()
Tells if theGSprite
should behave as a circular list.
The default value istrue
.boolean
Tells if theGSprite
is visibleiterator()
void
last()
Sets the lastGPixMap
as the current one.boolean
next()
Passes to the nextGPixMap
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 onisCyclic()
.boolean
prev()
Passes to the previousGPixMap
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 onisCyclic()
.boolean
Removes a givenmap
from the sprite.void
setCyclic
(boolean cyclic) Tells theGSprite
to act as if the list of elements is circular (cyclic), that means that when the lastGPixMap
is reached, then it will continue with the first one, and viceversa.
The default value istrue
.void
setDrawGrid
(boolean grid) Tells theGSprite
to draw the inner/outer linesvoid
setPixelSize
(int px) Sets a new pixel size for all of theGPixMap
of thisGSprite
void
setSkips
(int s) void
setVisible
(boolean visible) Tells theGSprite
if it should draw itselfint
skips()
void
traslate
(int x, int y) Traslates this element on X and YMethods 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
-
GSprite
public GSprite()Creates an empty sprite
-
-
Method Details
-
append
Append a newGPixMap
to thisGSprite
, this method will skip allGPixMap
that are already in theGSprite
- Parameters:
map
-GPixMap
to add- Throws:
IllegalArgumentException
- ifmap
isnull
InvalidArgumentException
- if themap
doesn't have the same size.
-
remove
Removes a givenmap
from 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:
true
if the element was found and removed andfalse
otherwise- Throws:
IllegalArgumentException
- ifmap
isnull
-
getCursor
public int getCursor()Retrieves the current cursor position- Returns:
- cursor position
-
first
public void first()Sets the firstGPixMap
as the current one. -
prev
public boolean prev()Passes to the previousGPixMap
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 onisCyclic()
.- Returns:
true
the pixmap change andfalse
otherwise.- See Also:
-
next
public boolean next()Passes to the nextGPixMap
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 onisCyclic()
.- Returns:
true
the pixmap change andfalse
otherwise.- See Also:
-
last
public void last()Sets the lastGPixMap
as the current one. -
isCyclic
public boolean isCyclic()Tells if theGSprite
should behave as a circular list.
The default value istrue
.- Returns:
true
if theGSprite
is circular, andfalse
otherwise.- See Also:
-
setCyclic
public void setCyclic(boolean cyclic) Tells theGSprite
to act as if the list of elements is circular (cyclic), that means that when the lastGPixMap
is reached, then it will continue with the first one, and viceversa.
The default value istrue
.- Parameters:
cyclic
-true
if theGSprite
should act as circular, andfalse
otherwise.- 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
- ifs
is 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 theGPixMap
of 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 theGSprite
to draw the inner/outer lines- Parameters:
grid
-true
to draw the lines andfalse
otherwise
-
drawGrid
public boolean drawGrid()Tells if theGSprite
will draw the inner lines or not- Returns:
true
if theGSprite
is drawing the inner lines andfalse
otherwise
-
getBounds
Retrieves the current bounds of thisGSprite
- Returns:
- bounds of this GSprite
-
setVisible
public void setVisible(boolean visible) Tells theGSprite
if it should draw itself- Parameters:
visible
-true
if theGSprite
should be drawn andfalse
otherwise
-
isVisible
public boolean isVisible()Tells if theGSprite
is visible- Returns:
true
if theGSprite
is visible andfalse
otherwise
-
draw
Description copied from class:GraphicE
Draws the component on the given graphics -
clone
-
traslate
public void traslate(int x, int y) Description copied from class:GraphicE
Traslates this element on X and Y -
iterator
-