topical media & game development
actionscript-misc-SpaceMap.ax
actionscript-misc-SpaceMap.ax
[swf]
flex
package {
import flash.display.*;
import flash.geom.*;
import flash.events.*;
// Creates and displays a draggable "outer space" graphic made up of
// individual tiles.
public class @ax-actionscript-misc-SpaceMap extends flash.display.Sprite {
private var spaceMap:actionscript_misc_TileMap; // A map containing the locations of
// space graphic tiles
private var tiles:actionscript_misc_TileSet; // The individual space tile graphics
// An on-screen, draggable display of spaceMap
private var draggableSpaceMap:actionscript_misc_DraggableMapRegion;
// Constructor
public function @ax-actionscript-misc-SpaceMap () {
// Prevent the application from resizing
stage.scaleMode = StageScaleMode.NO_SCALE;
// Create a new, empty map in which to store
// tile IDs (10 across by 15 down).
spaceMap = new actionscript_misc_TileMap(10, 15);
// Load the space tile graphic, and break it into individual tiles,
// sized 16-pixels square. For a demo with more obvious tiles,
// change "spacetiles.gif" to "tiles.gif".
tiles = new actionscript_misc_TileSet();
tiles.addEventListener(actionscript_misc_TileSet.TILES_LOADED, tilesLoadedListener);
tiles.loadTiles("actionscript-misc-assets-spacetiles.gif", 16);
}
// When the tile graphic loads, start the application
private function tilesLoadedListener (e:Event):void {
start();
}
// Creates an on-screen, draggable display of spaceMap
private function start ():void {
// First, randomly assign a tile ID to each position on the map
spaceMap.randomize(tiles.getNumTiles());
// Then create a new map viewer that supports dragging. The viewer
// will display an 80x80 pixel square section of the map, initially
// positioned at pixel coordinate (30, 40).
draggableSpaceMap = new actionscript_misc_DraggableMapRegion(spaceMap, tiles,
new Rectangle(30, 40, 80, 80));
// Display the map viewer on screen
addChild(draggableSpaceMap);
// For expository purposes, display the entire map with no scrolling.
// The map grid is 10 by 15, and each tile is 16 pixels square, so
// the entire displayed map is 160 by 240.
var wholeSpaceMap:actionscript_misc_TileMapViewer =
new actionscript_misc_TileMapViewer(spaceMap, tiles, new Rectangle(0, 0, 160, 240));
addChild(wholeSpaceMap);
wholeSpaceMap.x = 100;
}
}
}
(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.