com.siemens.mp.game
Class GraphicObjectManager

java.lang.Object
  extended bycom.siemens.mp.misc.NativeMem
      extended bycom.siemens.mp.game.GraphicObjectManager

public class GraphicObjectManager
extends com.siemens.mp.misc.NativeMem

The GraphicObjectManager implements graphic object collections. It holds GraphicObject class objects and their descendants, such as Sprite and TiledBackground.

GraphicObjectManager provides functionality for managing objects in a collection (insertion, deletion, search) and drawing an entire collection of graphic objects (layer by layer, from first to last object) on a given Image or ExtendedImage object.

See Also:
GraphicObject, Sprite, TiledBackground

Example


Constructor Summary
GraphicObjectManager()
          Initializes GraphicObjectManager.
 
Method Summary
 void addObject(GraphicObject gobject)
          Adds a new GraphicObject to the collection at the end of its list of objects.
static byte[] createTextureBits(int width, int height, byte[] texture)
          Converts a texture from byte per pixel into bit per pixel representation.
 void deleteObject(GraphicObject gobject)
          Removes the specified GraphicObject from the collection.
 void deleteObject(int position)
          Removes from a collection the GraphicObject specified by its position in the list.
 GraphicObject getObjectAt(int index)
          Returns the GraphicObject at the specified position in the list.
 int getObjectPosition(GraphicObject gobject)
          Returns the specified GraphicObject's position in the list.
 void insertObject(GraphicObject gobject, int position)
          Inserts a new GraphicObject into the collection at the specified position.
 void paint(ExtendedImage eimage, int x, int y)
          Draws all objects in the collection on the specified ExtendedImage.
 void paint(Image image, int x, int y)
          Draws all objects in the collection on the specified offscreen image.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphicObjectManager

public GraphicObjectManager()
Initializes GraphicObjectManager.

Example

Method Detail

addObject

public void addObject(GraphicObject gobject)
Adds a new GraphicObject to the collection at the end of its list of objects. On paint method call, the entire collection will be drawn in order, from the first to the last element (like layers).

Parameters:
gobject - the GraphicObject to add

Example


insertObject

public void insertObject(GraphicObject gobject,
                         int position)
Inserts a new GraphicObject into the collection at the specified position. It shifts up the object that previously occupied that position, and all the subsequent objects. On paint method call, the entire collection will be drawn from the first to the last element (like layers).

Parameters:
gobject - the GraphicObject to insert
position - the position at which this object is to be inserted (0 for the first object)

Example


getObjectPosition

public int getObjectPosition(GraphicObject gobject)
Returns the specified GraphicObject's position in the list.

Parameters:
gobject - the GraphicObject
Returns:
the object's position in the list (0 for the first object, -1 if the object is not in the collection)

Example


getObjectAt

public GraphicObject getObjectAt(int index)
Returns the GraphicObject at the specified position in the list.

Parameters:
index - the position in the list (0 for the first object)
Returns:
the GraphicObject at the specified position

Example


deleteObject

public void deleteObject(GraphicObject gobject)
Removes the specified GraphicObject from the collection. All the subsequent objects (if any) are shifted down.

Parameters:
gobject - the GraphicObject to remove

Example


deleteObject

public void deleteObject(int position)
Removes from a collection the GraphicObject specified by its position in the list. All the subsequent objects (if any) are shifted down.

Parameters:
position - the position of the object to remove (0 for the first object)

Example


paint

public void paint(Image image,
                  int x,
                  int y)
           throws IllegalArgumentException
Draws all objects in the collection on the specified offscreen image. Objects will be drawn from the first to the last one (like layers).

Parameters:
image - a standard Image (without transparency)
x - the x coordinate of the drawing area starting point (relative to the image)
y - the y coordinate of the drawing area starting point (relative to the image)
Throws:
IllegalArgumentException - if an image with transparent color is used

Example


paint

public void paint(ExtendedImage eimage,
                  int x,
                  int y)
           throws IllegalArgumentException
Draws all objects in the collection on the specified ExtendedImage. Objects will be drawn from the first to the last one (like layers).

Parameters:
eimage - an ExtendedImage (without transparency)
x - the x coordinate of the drawing area starting point (relative to the image)
y - the y coordinate of the drawing area starting point (relative to the image)
Throws:
IllegalArgumentException - if an image with transparent color is used

Example


createTextureBits

public static byte[] createTextureBits(int width,
                                       int height,
                                       byte[] texture)
Converts a texture from byte per pixel into bit per pixel representation. This static method is not related to other GraphicObjectManager functionalities, but it is quite useful to create byte per pixel arrays used as parameters in constructors of GraphicObject descendants (such as Sprite and TiledBackground) and of other objects (such as Image and ExtendedImage)
 Example of converting texture representation:
 
 The source byte per pixel array:
 {
   0,0,0,0,0,0,0,0,
   0,0,1,1,1,1,0,0,
   1,1,1,1,1,0,0,0,
 }
 The resulting bit per pixel array (complement of two):
 {
    0,
	60,
   -8,
 }
 

Parameters:
width - the width of the texture in pixels
height - the height of the texture in pixels
texture - the source byte per pixel array
Returns:
bit per pixel array

Example



Generated on 2003-10-17For further information and updates, please visit Siemens mobile Developer Portal