|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.golden.gamedev.object.SpriteGroup
SpriteGroup
is a group of sprites with common behaviour.
Use SpriteGroup
to manage sprites easily (updating and
rendering many sprites at once).
For example:
////////// Group for Enemy ////////// // creates the enemy sprites Sprite asteroid = new Sprite(), asteroid2 = new Sprite(); // the enemy SpriteGroup SpriteGroup ENEMY = new SpriteGroup("Enemy"); ENEMY.add(asteroid); ENEMY.add(asteroid2); // updating and rendering all sprites at once ENEMY.update(); ENEMY.render(Graphics2D);SpriteGroup is also be used by
CollisionGroup
.
Constructor Summary | |
SpriteGroup(String name)
Creates a new sprite group, with specified name. |
Method Summary | |
void |
add(int index,
Sprite member)
Inserts specified sprite into this group at specified index, the first sprite is the first to render. |
void |
add(Sprite member)
Inserts specified sprite into this group. |
void |
clear()
Removes all group members. |
Sprite |
getActiveMember()
Returns the first found active sprite or null if there is no active sprite. |
Background |
getBackground()
Background of this group. |
Comparator |
getComparator()
|
int |
getExpandFactor()
|
String |
getName()
Returns the name of this group. |
int |
getScanFrequence()
|
int |
getShrinkFactor()
|
int |
getSize()
Returns the size of this group. |
Sprite[] |
getSprites()
Returns all sprites (active, inactive, and also null sprite) in this group. |
Sprite |
remove(int index)
Removes a sprite at specified index from this group. |
boolean |
remove(Sprite s)
Removes specified sprite from this group. |
void |
render(Graphics2D g)
Renders all sprites in this group. |
void |
reset()
Removes all group members (same with clear()
except this method also removes sprite memory reference). |
void |
scanSprites()
Scans for inactive sprites to be thrown from this group. |
protected void |
scheduleToScan()
Schedule to scan inactive sprites based on scan frequence time. |
void |
setBackground(Background backgr)
|
void |
setComparator(Comparator c)
|
void |
setExpandFactor(int factor)
|
void |
setName(String name)
|
void |
setScanFrequence(int i)
|
void |
setShrinkFactor(int factor)
|
void |
sort(Comparator c)
|
String |
toString()
|
void |
update()
Updates all sprites in this group. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public SpriteGroup(String name)
Method Detail |
public void add(Sprite member)
public void add(int index, Sprite member)
public Sprite remove(int index)
public boolean remove(Sprite s)
public void reset()
clear()
except this method also removes sprite memory reference).
clear()
public void clear()
reset()
instead.
For example:
Destroying all enemies when player got a bomb.
ENEMY_GROUP.clear();
reset()
public void update()
public void sort(Comparator c)
public void render(Graphics2D g)
protected void scheduleToScan()
setScanFrequence(int)
,
scanSprites()
public void scanSprites()
setShrinkFactor(int)
public Sprite getActiveMember()
For example:
if (ENEMY.getActiveMember() == null) { // no active enemy, go to next level gameState = WIN; }
public int getScanFrequence()
public void setScanFrequence(int i)
public Comparator getComparator()
public void setComparator(Comparator c)
public String getName()
public void setName(String name)
public Sprite[] getSprites()
getSize()
public int getSize()
public int getExpandFactor()
public void setExpandFactor(int factor)
public int getShrinkFactor()
public void setShrinkFactor(int factor)
public Background getBackground()
public void setBackground(Background backgr)
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |