|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.golden.gamedev.object.SpriteGroup
com.golden.gamedev.object.AdvanceSpriteGroup
public class AdvanceSpriteGroup
Subclass of SpriteGroup
that designed to update and render
visible on the screen sprites only.
In standard sprite group, all registered sprites in the group is updated, rendered, and check for collision in every game loop. If the game has many sprites and many of them are not visible, it is not efficient to update, render, and check for collision all of the sprites.
AdvanceSpriteGroup
is designed to optimize the sprite updating
and rendering by updating and rendering sprites that only visible on screen,
sprites that outside the game view area are not checked.
The main operation is storing sprites that visible on screen into an inner sprite group, and the inner sprite group that will be update, render, and check for collision.
Field Summary | |
---|---|
protected SpriteGroup |
ONSCREEN_GROUP
Inner sprite group that hold on screen sprites (inside view area sprites) of this group. |
Constructor Summary | |
---|---|
AdvanceSpriteGroup(String name)
Creates new AdvanceSpriteGroup with specified name without
screen offset (0, 0, 0, 0). |
|
AdvanceSpriteGroup(String name,
int screenOffset)
Creates new AdvanceSpriteGroup with specified name, and
specified screen offset. |
|
AdvanceSpriteGroup(String name,
int topOffset,
int leftOffset,
int bottomOffset,
int rightOffset)
Creates new AdvanceSpriteGroup with specified name, and
specified screen offset on each side. |
Method Summary | |
---|---|
int |
getGroupSize()
Returns total non-null sprites (active + inactive) in this group. |
Sprite[] |
getGroupSprites()
Returns all sprites (active, inactive, and also null sprite) in this group. |
Insets |
getScreenOffset()
Returns screen offset of this group. |
int |
getSize()
Returns total non-null on-screen sprites (active + inactive sprites) in this group. |
Sprite[] |
getSprites()
Returns all on-screen sprites (active, inactive, and also null sprite) in this group. |
void |
render(Graphics2D g)
Renders all active sprites in this group. |
void |
setBackground(Background backgr)
Associates specified background with this sprite group, the background will be used by all sprites in this group. |
void |
setComparator(Comparator c)
Sets comparator used for sorting sprites in this group. |
void |
update(long elapsedTime)
Updates all active sprites in this group, and check the schedule for removing inactive sprites. |
Methods inherited from class com.golden.gamedev.object.SpriteGroup |
---|
add, add, clear, getActiveSprite, getBackground, getComparator, getExpandFactor, getInactiveSprite, getName, getScanFrequence, isActive, remove, remove, removeImmutableSprites, removeInactiveSprites, reset, setActive, setExpandFactor, setName, sort, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected SpriteGroup ONSCREEN_GROUP
Constructor Detail |
---|
public AdvanceSpriteGroup(String name, int topOffset, int leftOffset, int bottomOffset, int rightOffset)
AdvanceSpriteGroup
with specified name, and
specified screen offset on each side.
public AdvanceSpriteGroup(String name, int screenOffset)
AdvanceSpriteGroup
with specified name, and
specified screen offset.
public AdvanceSpriteGroup(String name)
AdvanceSpriteGroup
with specified name without
screen offset (0, 0, 0, 0).
Method Detail |
---|
public void update(long elapsedTime)
SpriteGroup
update
in class SpriteGroup
SpriteGroup.getScanFrequence()
public void render(Graphics2D g)
SpriteGroup
render
in class SpriteGroup
SpriteGroup.setComparator(Comparator)
public void setBackground(Background backgr)
SpriteGroup
setBackground
in class SpriteGroup
SpriteGroup.getBackground()
public void setComparator(Comparator c)
SpriteGroup
The comparator is used by
Arrays.sort(java.lang.Object[], int, int, java.util.Comparator)
to sort the sprites before rendering. For more information about how to
make comparator, please read java.util.Comparator and
java.util.Arrays#sort().
Example of sorting sprites based on y-axis :
SpriteGroup ENEMY_GROUP; ENEMY_GROUP.setComparator( new Comparator() { public int compare(Object o1, Object o2) { Sprite s1 = (Sprite) o1, s2 = (Sprite) o2; return (s1.getY() - s2.getY()); } } };
setComparator
in class SpriteGroup
c
- the sprite comparator, null for unsort orderComparator
,
Arrays.sort(java.lang.Object[], int, int, java.util.Comparator)
public Insets getScreenOffset()
public Sprite[] getSprites()
getSprites
in class SpriteGroup
getSize()
public int getSize()
getSize
in class SpriteGroup
SpriteGroup.getSprites()
public Sprite[] getGroupSprites()
getGroupSize()
public int getGroupSize()
|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |