Java Doc for TiledLayer.java in  » 6.0-JDK-Modules » j2me » javax » microedition » lcdui » game » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » javax.microedition.lcdui.game 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   javax.microedition.lcdui.game.Layer
      javax.microedition.lcdui.game.TiledLayer

TiledLayer
public class TiledLayer extends Layer (Code)
A TiledLayer is a visual element composed of a grid of cells that can be filled with a set of tile images. This class allows large virtual layers to be created without the need for an extremely large Image. This technique is commonly used in 2D gaming platforms to create very large scrolling backgrounds,

Tiles

The tiles used to fill the TiledLayer's cells are provided in a single Image object which may be mutable or immutable. The Image is broken up into a series of equally-sized tiles; the tile size is specified along with the Image. As shown in the figure below, the same tile set can be stored in several different arrangements depending on what is the most convenient for the game developer.
Tiles

Each tile is assigned a unique index number. The tile located in the upper-left corner of the Image is assigned an index of 1. The remaining tiles are then numbered consecutively in row-major order (indices are assigned across the first row, then the second row, and so on). These tiles are regarded as static tiles because there is a fixed link between the tile and the image data associated with it.

A static tile set is created when the TiledLayer is instantiated; it can also be updated at any time using the TiledLayer.setStaticTileSet method.

In addition to the static tile set, the developer can also define several animated tiles. An animated tile is a virtual tile that is dynamically associated with a static tile; the appearance of an animated tile will be that of the static tile that it is currently associated with.

Animated tiles allow the developer to change the appearance of a group of cells very easily. With the group of cells all filled with the animated tile, the appearance of the entire group can be changed by simply changing the static tile associated with the animated tile. This technique is very useful for animating large repeating areas without having to explicitly change the contents of numerous cells.

Animated tiles are created using the TiledLayer.createAnimatedTile method, which returns the index to be used for the new animated tile. The animated tile indices are always negative and consecutive, beginning with -1. Once created, the static tile associated with an animated tile can be changed using the TiledLayer.setAnimatedTile method.

Cells

The TiledLayer's grid is made up of equally sized cells; the number of rows and columns in the grid are specified in the constructor, and the physical size of the cells is defined by the size of the tiles.

The contents of each cell is specified by means of a tile index; a positive tile index refers to a static tile, and a negative tile index refers to an animated tile. A tile index of 0 indicates that the cell is empty; an empty cell is fully transparent and nothing is drawn in that area by the TiledLayer. By default, all cells contain tile index 0.

The contents of cells may be changed using TiledLayer.setCell and TiledLayer.fillCells . Several cells may contain the same tile; however, a single cell cannot contain more than one tile. The following example illustrates how a simple background can be created using a TiledLayer.

TiledLayer Grid

In this example, the area of water is filled with an animated tile having an index of -1, which is initially associated with static tile 5. The entire area of water may be animated by simply changing the associated static tile using setAnimatedTile(-1, 7).
TiledLayer Grid 2

Rendering a TiledLayer

A TiledLayer can be rendered by manually calling its paint method; it can also be rendered automatically using a LayerManager object.

The paint method will attempt to render the entire TiledLayer subject to the clip region of the Graphics object; the upper left corner of the TiledLayer is rendered at its current (x,y) position relative to the Graphics object's origin. The rendered region may be controlled by setting the clip region of the Graphics object accordingly.



Field Summary
 ImagesourceImage
    
 int[]tileSetX
    
 int[]tileSetY
    

Constructor Summary
public  TiledLayer(int columns, int rows, Image image, int tileWidth, int tileHeight)
     Creates a new TiledLayer.

Method Summary
public  intcreateAnimatedTile(int staticTileIndex)
     Creates a new animated tile and returns the index that refers to the new animated tile.
public  voidfillCells(int col, int row, int numCols, int numRows, int tileIndex)
     Fills a region cells with the specific tile.
public  intgetAnimatedTile(int animatedTileIndex)
     Gets the tile referenced by an animated tile.
public  intgetCell(int col, int row)
     Gets the contents of a cell.
final public  intgetCellHeight()
     Gets the height of a single cell, in pixels.
final public  intgetCellWidth()
     Gets the width of a single cell, in pixels.
final public  intgetColumns()
     Gets the number of columns in the TiledLayer grid.
final public  intgetRows()
     Gets the number of rows in the TiledLayer grid.
final public  voidpaint(Graphics g)
     Draws the TiledLayer.
public  voidsetAnimatedTile(int animatedTileIndex, int staticTileIndex)
     Associates an animated tile with the specified static tile.
public  voidsetCell(int col, int row, int tileIndex)
     Sets the contents of a cell.
public  voidsetStaticTileSet(Image image, int tileWidth, int tileHeight)
     Change the static tile set.

Field Detail
sourceImage
Image sourceImage(Code)
Source image for tiles



tileSetX
int[] tileSetX(Code)
X co-ordinate definitions for individual frames into the source image



tileSetY
int[] tileSetY(Code)
Y co-ordinate definitions for individual frames into the source image




Constructor Detail
TiledLayer
public TiledLayer(int columns, int rows, Image image, int tileWidth, int tileHeight)(Code)
Creates a new TiledLayer.

The TiledLayer's grid will be rows cells high and columns cells wide. All cells in the grid are initially empty (i.e. they contain tile index 0). The contents of the grid may be modified through the use of TiledLayer.setCell and TiledLayer.fillCells .

The static tile set for the TiledLayer is created from the specified Image with each tile having the dimensions of tileWidth x tileHeight. The width of the source image must be an integer multiple of the tile width, and the height of the source image must be an integer multiple of the tile height; otherwise, an IllegalArgumentException is thrown;

The entire static tile set can be changed using TiledLayer.setStaticTileSet(Image,int,int) . These methods should be used sparingly since they are both memory and time consuming. Where possible, animated tiles should be used instead to animate tile appearance.


Parameters:
  columns - the width of the TiledLayer,expressed as a number of cells
Parameters:
  rows - the height of the TiledLayer,expressed as a number of cells
Parameters:
  image - the Image to use for creatingthe static tile set
Parameters:
  tileWidth - the width in pixels of a single tile
Parameters:
  tileHeight - the height in pixels of a single tile
throws:
  NullPointerException - if image is null
throws:
  IllegalArgumentException - if the number of rowsor columns is less than 1
throws:
  IllegalArgumentException - if tileHeightor tileWidth is less than 1
throws:
  IllegalArgumentException - if the imagewidth is not an integer multiple of the tileWidth
throws:
  IllegalArgumentException - if the imageheight is not an integer multiple of the tileHeight





Method Detail
createAnimatedTile
public int createAnimatedTile(int staticTileIndex)(Code)
Creates a new animated tile and returns the index that refers to the new animated tile. It is initially associated with the specified tile index (either a static tile or 0).

The indices for animated tiles are always negative. The first animated tile shall have the index -1, the second, -2, etc.
Parameters:
  staticTileIndex - the index of the associated tile (must be 0 or a valid static tile index) the index of newly created animated tile
throws:
  IndexOutOfBoundsException - if the staticTileIndex is invalid




fillCells
public void fillCells(int col, int row, int numCols, int numRows, int tileIndex)(Code)
Fills a region cells with the specific tile. The cells may be filled with a static tile index, an animated tile index, or they may be left empty (index 0).
Parameters:
  col - the column of top-left cell in the region
Parameters:
  row - the row of top-left cell in the region
Parameters:
  numCols - the number of columns in the region
Parameters:
  numRows - the number of rows in the region
Parameters:
  tileIndex - the Index of the tile to place in all cells in the specified region
throws:
  IndexOutOfBoundsException - if the rectangular regiondefined by the parameters extends beyond the bounds of theTiledLayer grid
throws:
  IllegalArgumentException - if numCols is lessthan zero
throws:
  IllegalArgumentException - if numRows is lessthan zero
throws:
  IndexOutOfBoundsException - if there is no tile withindex tileIndex
See Also:   TiledLayer.setCell
See Also:   TiledLayer.getCell



getAnimatedTile
public int getAnimatedTile(int animatedTileIndex)(Code)
Gets the tile referenced by an animated tile.

Returns the tile index currently associated with the animated tile.
Parameters:
  animatedTileIndex - the index of the animated tile the index of the tile reference by the animated tile
throws:
  IndexOutOfBoundsException - if the animated tile indexis invalid
See Also:   TiledLayer.setAnimatedTile




getCell
public int getCell(int col, int row)(Code)
Gets the contents of a cell.

Gets the index of the static or animated tile currently displayed in a cell. The returned index will be 0 if the cell is empty.
Parameters:
  col - the column of cell to check
Parameters:
  row - the row of cell to check the index of tile in cell
throws:
  IndexOutOfBoundsException - if row orcol is outside the bounds of the TiledLayer grid
See Also:   TiledLayer.setCell
See Also:   TiledLayer.fillCells




getCellHeight
final public int getCellHeight()(Code)
Gets the height of a single cell, in pixels. the height in pixels of a single cell in the TiledLayer grid



getCellWidth
final public int getCellWidth()(Code)
Gets the width of a single cell, in pixels. the width in pixels of a single cell in the TiledLayer grid



getColumns
final public int getColumns()(Code)
Gets the number of columns in the TiledLayer grid. The overall width of the TiledLayer, in pixels, may be obtained by calling TiledLayer.getWidth . the width in columns of the TiledLayer grid



getRows
final public int getRows()(Code)
Gets the number of rows in the TiledLayer grid. The overall height of the TiledLayer, in pixels, may be obtained by calling TiledLayer.getHeight . the height in rows of the TiledLayer grid



paint
final public void paint(Graphics g)(Code)
Draws the TiledLayer. The entire TiledLayer is rendered subject to the clip region of the Graphics object. The TiledLayer's upper left corner is rendered at the TiledLayer's current position relative to the origin of the Graphics object. The current position of the TiledLayer's upper-left corner can be retrieved by calling TiledLayer.getX() and TiledLayer.getY() . The appropriate use of a clip region and/or translation allows an arbitrary region of the TiledLayer to be rendered.

If the TiledLayer's Image is mutable, the TiledLayer is rendered using the current contents of the Image.
Parameters:
  g - the graphics object to draw the TiledLayer
throws:
  NullPointerException - if g is null




setAnimatedTile
public void setAnimatedTile(int animatedTileIndex, int staticTileIndex)(Code)
Associates an animated tile with the specified static tile.


Parameters:
  animatedTileIndex - the index of the animated tile
Parameters:
  staticTileIndex - the index of the associated tile(must be 0 or a valid static tile index)
throws:
  IndexOutOfBoundsException - if the staticTileIndex is invalid
throws:
  IndexOutOfBoundsException - if the animated tile indexis invalid
See Also:   TiledLayer.getAnimatedTile




setCell
public void setCell(int col, int row, int tileIndex)(Code)
Sets the contents of a cell.

The contents may be set to a static tile index, an animated tile index, or it may be left empty (index 0)
Parameters:
  col - the column of cell to set
Parameters:
  row - the row of cell to set
Parameters:
  tileIndex - the index of tile to place in cell
throws:
  IndexOutOfBoundsException - if there is no tile with indextileIndex
throws:
  IndexOutOfBoundsException - if row orcol is outside the bounds of the TiledLayer grid
See Also:   TiledLayer.getCell
See Also:   TiledLayer.fillCells




setStaticTileSet
public void setStaticTileSet(Image image, int tileWidth, int tileHeight)(Code)
Change the static tile set.

Replaces the current static tile set with a new static tile set. See the constructor TiledLayer.TiledLayer(int,int,Image,int,int) for information on how the tiles are created from the image.

If the new static tile set has as many or more tiles than the previous static tile set, the the animated tiles and cell contents will be preserve. If not, the contents of the grid will be cleared (all cells will contain index 0) and all animated tiles will be deleted.


Parameters:
  image - the Image to use for creating thestatic tile set
Parameters:
  tileWidth - the width in pixels of a single tile
Parameters:
  tileHeight - the height in pixels of a single tile
throws:
  NullPointerException - if image is null
throws:
  IllegalArgumentException - if tileHeightor tileWidth is less than 1
throws:
  IllegalArgumentException - if the imagewidth is not an integer multiple of the tileWidth
throws:
  IllegalArgumentException - if the imageheight is not an integer multiple of the tileHeight




Fields inherited from javax.microedition.lcdui.game.Layer
int height(Code)(Java Doc)
boolean visible(Code)(Java Doc)
int width(Code)(Java Doc)
int x(Code)(Java Doc)
int y(Code)(Java Doc)

Methods inherited from javax.microedition.lcdui.game.Layer
final public int getHeight()(Code)(Java Doc)
final public int getWidth()(Code)(Java Doc)
final public int getX()(Code)(Java Doc)
final public int getY()(Code)(Java Doc)
final public boolean isVisible()(Code)(Java Doc)
public void move(int dx, int dy)(Code)(Java Doc)
abstract public void paint(Graphics g)(Code)(Java Doc)
void setHeightImpl(int height)(Code)(Java Doc)
public void setPosition(int x, int y)(Code)(Java Doc)
public void setVisible(boolean visible)(Code)(Java Doc)
void setWidthImpl(int width)(Code)(Java Doc)

Methods inherited from java.lang.Object
public boolean equals(Object obj)(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.