com.golden.gamedev.genre.platform
Class PlatformGroup

java.lang.Object
  |
  +--com.golden.gamedev.object.SpriteGroup
        |
        +--com.golden.gamedev.genre.platform.PlatformGroup

public class PlatformGroup
extends SpriteGroup

SpriteGroup designed to fit platform game.

In standard sprite group, all registered sprites in the group is updated and rendered every game loop, collision check also checked with all sprites in the group.

In platform game, there are so many sprites, for example: tile blocks, enemies, projectiles, etc.
If there are 10000 tile blocks in a platform game, for one player sprite, we must check for 1 x 10000 = 10000 collision check.
If there are many projectiles fired by the player, and many enemies standing in his way, the collision check will be more than one million!
That's only for collision check, the sprites still have to be updated and rendered every game loop.

Therefore PlatformGroup is specially designed to hold many sprites in platform game.
The mainly operation of this group is storing only a sprite that's visible on screen. All registered sprites is backed up, and only on screen sprites is updated, rendered, and check for it's collision.


Constructor Summary
PlatformGroup(String name)
           
PlatformGroup(String name, int screenOffset)
           
PlatformGroup(String name, int leftOffset, int topOffset, int rightOffset, int bottomOffset)
           
 
Method Summary
 int getAllSize()
           
 Sprite[] getAllSprites()
          Returns all registered sprite in this group, same as SpriteGroup.getSprites().
 SpriteGroup getOnScreenGroup()
           
 int getSize()
          Returns total on screen sprites
 Sprite[] getSprites()
          Returns on screen sprites
 void render(Graphics2D g)
          Renders all sprites in this group.
 void setBackground(Background backgr)
           
 void setComparator(Comparator c)
           
 void setOnScreenGroup(SpriteGroup group)
           
 void update()
          Updates all sprites in this group.
 
Methods inherited from class com.golden.gamedev.object.SpriteGroup
add, add, clear, getActiveMember, getBackground, getComparator, getExpandFactor, getName, getScanFrequence, getShrinkFactor, remove, remove, reset, scanSprites, scheduleToScan, setExpandFactor, setName, setScanFrequence, setShrinkFactor, sort, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PlatformGroup

public PlatformGroup(String name,
                     int leftOffset,
                     int topOffset,
                     int rightOffset,
                     int bottomOffset)

PlatformGroup

public PlatformGroup(String name,
                     int screenOffset)

PlatformGroup

public PlatformGroup(String name)
Method Detail

update

public void update()
Description copied from class: SpriteGroup
Updates all sprites in this group.

Overrides:
update in class SpriteGroup

render

public void render(Graphics2D g)
Description copied from class: SpriteGroup
Renders all sprites in this group.

Overrides:
render in class SpriteGroup

setBackground

public void setBackground(Background backgr)
Overrides:
setBackground in class SpriteGroup

setComparator

public void setComparator(Comparator c)
Overrides:
setComparator in class SpriteGroup

getOnScreenGroup

public SpriteGroup getOnScreenGroup()

setOnScreenGroup

public void setOnScreenGroup(SpriteGroup group)

getSprites

public Sprite[] getSprites()
Returns on screen sprites

Overrides:
getSprites in class SpriteGroup
See Also:
SpriteGroup.getSize()

getSize

public int getSize()
Returns total on screen sprites

Overrides:
getSize in class SpriteGroup

getAllSprites

public Sprite[] getAllSprites()
Returns all registered sprite in this group, same as SpriteGroup.getSprites().


getAllSize

public int getAllSize()