if (!this.isVisible) { return; }
	public final void paint( Graphics g)	{		int clipX = g.getClipX();		int clipY = g.getClipY();		int clipWidth = g.getClipWidth();		int clipHeight = g.getClipHeight();		// set first and last column:		int firstColumn = 0;		int lastColumn;		if (this.xPosition < clipX) {			firstColumn = (clipX - this.xPosition) / this.cellWidth;			lastColumn = ((clipX - this.xPosition + clipWidth) / this.cellWidth) + 1;			//System.out.println("setting columnStart=" + firstColumn + " clipWidth=" + clipWidth + " cellWidth=" + this.cellWidth );		} else {			lastColumn = (clipWidth / this.cellWidth) + 1; 		}		if (lastColumn > this.gridColumns) {			lastColumn = this.gridColumns;		}		// set first and last row:		int firstRow = 0;		int lastRow;		if (this.yPosition < clipY) {			firstRow = (clipY - this.yPosition) / this.cellHeight;			lastRow = ((clipY - this.yPosition + clipHeight) / this.cellHeight) + 1;		} else {			lastRow = (clipHeight / this.cellHeight) + 1;		}		if (lastRow > this.gridRows) {			lastRow = this.gridRows;		}				// set initial x and y positions:		int xStart = this.xPosition + (firstColumn * this.cellWidth);		int yStart = this.yPosition + (firstRow * this.cellHeight);				// check if the tiled layer is within the viewport at all:		// note: this should be done by the layer manager		/*		if (xStart > clipX + clipWidth			|| yStart > clipY + clipHeight			|| xStart + this.width < clipX			|| yStart + this.height < clipY )			{			return;		}		*/		 		int y = yStart;		int x = xStart;				int[][] gridTable = this.grid;		//#ifdef tmp.useBackBuffer			x = 0;			y = 0;			// create back buffer when it is null:			boolean clearBuffer = false;			if (this.bufferGrid == null) {				clearBuffer = true;				this.bufferGrid = new int[ this.gridColumns ][ this.gridRows ];				this.bufferImage = Image.createImage( 					this.cellWidth * ((clipWidth / this.cellWidth) + 2),					this.cellHeight * ((clipHeight / this.cellHeight) + 2) );				this.bufferGraphics = this.bufferImage.getGraphics();				this.bufferFirstColumn = firstColumn;				this.bufferFirstRow = firstRow;			} else if ( this.bufferFirstColumn != firstColumn 					|| this.bufferFirstRow != firstRow) 			{				//System.out.println("clearing backbuffer");				clearBuffer = true;				this.bufferFirstColumn = firstColumn;				this.bufferFirstRow = firstRow;			}			Graphics originalGraphics = g;			g = this.bufferGraphics;			g.setColor( this.bufferTransparentColor );			if (clearBuffer) {				g.fillRect( 0, 0, this.bufferImage.getWidth(), this.bufferImage.getHeight() );			}		//#elif tmp.splitTiles && polish.api.nokia-ui && ! tmp.useBackBuffer			DirectGraphics dg = DirectUtils.getDirectGraphics(g);		//#endif				// now paint the single tiles either directly to the screen		// or to the backbuffer:		for (int column = firstColumn; column < lastColumn; column++) {			int[] gridColumn = gridTable[column];			for (int row = firstRow; row < lastRow; row++) {				int cellIndex = gridColumn[row];				if (cellIndex != 0) {					// okay this cell needs to be rendered:					int tileIndex;					if (cellIndex < 0) {						tileIndex = this.animatedTiles[ (-1 * cellIndex ) -1  ] - 1;					} else {						tileIndex = cellIndex -1;					}					//#ifdef tmp.useBackBuffer						if (!clearBuffer && tileIndex == this.bufferGrid[ column ][ row ]) {							// the tile has been painted already to the backbuffer,							// so continue this loop:							if (!(row >= this.bufferLastRow || column >= this.bufferLastColumn)) {								y += this.cellHeight;								continue;							}						} 					//#endif					// now draw the tile:					//#ifndef tmp.splitTiles						// paint the tile the traditional way:						// slower but using less memory,						// this is also the only way for plain MIDP1-devices						// to keep the transparency of tiles: 						g.setClip( x, y, this.cellWidth, this.cellHeight );						//#ifndef tmp.useBackBuffer							// 4 variables would need to be compared, so set the 							// intersection with the original clip in all cases: 							g.clipRect( clipX, clipY, clipWidth, clipHeight );						//#endif						int tileColumn = tileIndex % this.numberOfColumns;						int tileRow = tileIndex / this.numberOfColumns; 						int tileX = x - this.tileXPositions[ tileColumn ];						int tileY = y - this.tileYPositions[ tileRow ];						g.drawImage( this.image, tileX, tileY, Graphics.TOP | Graphics.LEFT );					//#else						// paint a single tile: faster, but needs more memory.						// Also any transparency is lost, when no 						// Nokia-UI API is available:						Image tile = this.tiles[ tileIndex ];						//#ifdef tmp.useBackBuffer							g.drawImage( tile, x, y, Graphics.TOP | Graphics.LEFT );						//#elif polish.api.nokia-ui							dg.drawImage( tile, x, y, Graphics.TOP | Graphics.LEFT, 0 );						//#else							g.drawImage( tile, x, y, Graphics.TOP | Graphics.LEFT );						//#endif					//#endif					//#ifdef tmp.useBackBuffer						this.bufferGrid[ column ][ row ] = tileIndex;					//#endif				//#ifndef tmp.useBackBuffer					//# }				//#else					} else if (this.bufferGrid[ column ][ row ] != 0) {						// fill this cell with the background-color,						// the color has been set before this loop:						g.fillRect( x, y, this.cellWidth, this.cellHeight );						this.bufferGrid[ column ][ row ] = 0;					}				//#endif				y += this.cellHeight;			} // for each row			//#ifdef tmp.useBackBuffer				y = 0;			//#else				y = yStart;			//#endif			x += this.cellWidth;		} // for each column				//#ifdef tmp.useBackBuffer			// now paint the backbuffer to the screen:			originalGraphics.drawImage( this.bufferImage, xStart, yStart, Graphics.TOP | Graphics.LEFT );			// save last row and column for the next paint() call:			this.bufferLastColumn = lastColumn;			this.bufferLastRow = lastRow; 		//#endif				// reset original clip:		//#ifndef tmp.splitTiles			g.setClip( clipX, clipY, clipWidth, clipHeight );		//#endif	}