topical media & game development
actionscript-misc-TileMapViewer.ax
actionscript-misc-TileMapViewer.ax
[swf]
flex
package {
import flash.display.*;
import flash.geom.*;
// Displays a rectangular region of a TileMap using a specified TileSet.
// By default @ax-actionscript-misc-TileMapViewer uses TileMapRenderer as its rendering
// utility class. This default renderer can be replaced with a more
// efficient renderer via @ax-actionscript-misc-TileMapViewer.setRenderer().
public class @ax-actionscript-misc-TileMapViewer extends Bitmap {
private var map:actionscript_misc_TileMap; // The map to display
private var tiles:actionscript_misc_TileSet; // The tiles used to render the map
private var renderer:actionscript_misc_ITileMapRenderer; // Rendering utility object
private var viewRect:Rectangle; // The region to display
// Constructor
public function @ax-actionscript-misc-TileMapViewer (map:actionscript_misc_TileMap,
tiles:actionscript_misc_TileSet,
rect:Rectangle) {
// Use a temporary dummy BitmapData object for the super() call.
// The dummy BitmapData object is replaced by setViewRect()
// before this constructor function returns.
// ##[the dummy might not be required in the final. see bug 162774]
super(new BitmapData(1,1));
// Set the map, tiles, renderer, and region to display
setMap(map);
setTiles(tiles);
setRenderer(new actionscript_misc_TileMapRenderer());
setViewRect(rect);
}
// Displays a rectangular region of the tile map
public function setViewRect (rect:Rectangle):void {
viewRect = rect;
bitmapData = renderer.getRenderedRegionByPixels(rect);
}
// Returns a rectangle indicating which region of
// the tile map is currently displayed
public function getViewRect ():Rectangle {
return viewRect.clone();
}
// Sets the tile map to be displayed
public function setMap (newMap:actionscript_misc_TileMap):void {
map = newMap;
}
// Sets the tiles from which the tile map will be rendered
public function setTiles (newTiles:actionscript_misc_TileSet):void {
tiles = newTiles;
}
// Sets the utility class that will render the map
public function setRenderer (newRenderer:actionscript_misc_ITileMapRenderer):void {
renderer = newRenderer;
renderer.setMap(map);
renderer.setTiles(tiles);
}
}
}
(C) Æliens
27/08/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.