In order to optimize for faster performance than individual drawing calls, the Tilesheet provides an alternative API with several constraints to play nicely with hardware rendering. First, every Tilesheet can only use one BitmapData as a texture. This restriction provides the opportunity to copy only one texture to the GPU memory before rendering. Second, the Tilesheet uses pre-defined geometry. You may make as many calls as you want to "addTileRect" to add tile geometry. You can reference this geometry later when you perform batch rendering, using a zero-based ID for the tile. When you are ready, the "drawTiles" method accepts a draw list with the ID of the tile, as well as additional values needed, depending on whether you are only rendering with the tile position, or if you have enabled flags for

  • Lib.Media.Display.Tilesheet.TILE_SCALE
  • Lib.Media.Display.Tilesheet.TILE_ROTATION
  • Lib.Media.Display.Tilesheet.TILE_RGB
  • Lib.Media.Display.Tilesheet.TILE_ALPHA
  • Lib.Media.Display.Tilesheet.TILE_TRANS_2x2
  • Lib.Media.Display.Tilesheet.TILE_RECT
  • Lib.Media.Display.Tilesheet.TILE_ORIGIN
  • Lib.Media.Display.Tilesheet.TILE_NO_ID
  • Lib.Media.Display.Tilesheet.TILE_MOUSE_ENABLE
  • Lib.Media.Display.Tilesheet.TILE_FIXED_SIZE
  • Lib.Media.Display.Tilesheet.TILE_BLEND_NORMAL


Can be created with method new:

Lib.Media.Display.Tilesheet.new(bitmapdata)

creates Tilesheeit object from bitmapdata.

bitmapdata - BitmapData object


created Tilesheet object has methods:

addTileRect(rectangle, centerPoint)

Add a new tile to the Tilesheet Beginning with 0, each tile is assigned an indentifier internally, which you can use to reference the geometry later while rendering. For example, if you have only called "addTileRect" once on a Tilesheet, you would reference that tile using a tile ID of 0. If you have called "addTileRect" three times, the third tile would have an ID of 2. Specify a rectangle within the bounds of the Tilesheet bitmap. This portion of the Tilesheet will be rendered when ever you request a draw of this tile ID. You may also (can be nil) specify a centerPoint, which is used during positioning, scale and rotation. The center point should be a coordinate within the tile rectangle.

rectangle - Rectangle object

centerPoint - Point object

getTileRect(index, rect)

Return tile rectangle for tile with index ID. rect object you need to use for result, can be nil. If nil method creates new rectangle.

index - tile index, int

rect - Rectangle object

drawTiles(graphics, tileData, smooth, flags, count)

Fast method to render a batch of tiles from the Tilesheet graphic A standard "drawTiles" call expects a repeating set of three values: the X and Y coordinates, followed by the tileID that should be rendered. You can repeat this pattern for as many tiles you wish to render. If you specify drawing flags, the draw list increases in size to accommodate the additional properties needed. You may specify TILE_SCALE, TILE_ROTATION, TILE_RGB and/or TILE_ALPHA. This means that the draw list will increase from x, y, tileID ... to x, y, tileID, scale, rotation, red, green, blue, alpha ... depending on which flags are active. If you use the TILE_TRANS_2x2 flag, it means you wish to use a 2x2 Matrix transform while rendering. If you use TILE_TRANS_2x2, the TILE_SCALE and TILE_ROTATION flags will be ignored. Using this flag, the draw list will expect the following order: x, y, tileID, a, b, c, d, red, green, blue, alpha ... ...of course, if you are not using TILE_RGB or TILE_ALPHA, then you would repeat the pattern directly following the matrix "a", "b", "c" and "d" values.

graphics - The Graphics object to use for drawing

tileData - An array of all position, ID and optional values for use in drawing

smooth - Whether tiles should be smoothed while drawing(Recommended default: false)

flags - Flags to enable scale, rotation, RGB and/or alpha when drawing(Recommended default: 0)

count - data size, int (recommended default -1, means use all tileData positions)

Created with the Personal Edition of HelpNDoc: Produce online help for Qt applications