LayerManager





LayerManager

The LayerManager manages a series of Layers and simplifies the rendering process by automatically drawing the correct regions of each Layer in the appropriate order.

The LayerManager maintains an ordered list to which Layers can be appended, inserted, and removed. A Layer's index correlates to its z-order; the layer at index 0 is closest to the user while the Layer with the highest index is furthest away from the user. The indices are always contiguous; that is, if a Layer is removed, the indices of subsequent Layers will be adjusted to maintain continuity.

The LayerManager class provides several features that control how the game's Layers are rendered on the screen. The size of the view window controls how large the user's view will be, and is usually fixed at a size that is appropriate for the device's screen.

The position of the view window can also be adjusted relative to the LayerManager's coordinate system. Changing the position of the view window enables effects such as scrolling or panning the user's view. For example, to scroll to the right, simply move the view window's location to the right.

In the example shown in Figure, the view window is set to a region that is 120 pixels wide, 120 pixels high, and located at (102, 40) in the LayerManager's coordinate system.

layerMgr.setViewWindow(102, 40, 120, 120);
11. Setting the view window

graphics/12fig11.jpg

The paint method of LayerManager class includes an (x,y) location that controls where the contents of the view window are rendered relative to the screen. Changing these parameters does not ch ange the contents of the view window; it simply changes the location where the view window is drawn on the screen. Note that this location is relative to the origin of the Graphics object, and thus it is subject to the translation attributes of the Graphics object.

For example, if a game uses the top of the screen to display the current score (Figure), the view window may be rendered at (0, 12) to provide space for the score.

layerMgr.paint(g, 0, 12);
12. The contents of the view window drawn at a specific location

graphics/12fig12.gif


     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows