Talking about Actionscript 3, Flash, Game development and Users contributions.
Almost a year ago I blogged about a basic level editor for a tile based game, and now Philipp Zins from Germany show us his AS3 level editor-
I made the level editor in ActionScript 3. You can scroll through the tiles with the mouse wheel – it isn’t necessary now, but very helpful if you use many, many tiles. You can change the map size and activate the “Generate”-Button by clicking or pressing Return.You can scroll the map, too. The finished array will be traced. The tile graphics are a little different – you will see that. I think I used some german words in the code, sorry.
Prepare yourself for a quite long source code…
/*1. variables
2.UI
2.1. map: height+width options, generate button
2.2. selectable tiles
3. functions
3.1. selectable tiles
3.1.1. current tile
3.1.2 scrolling
3.2. generate button
3.2.1. on Enter, too
3.2.2. generate map
3.2.2.1. get width, height
3.2.2.2. place containers
3.2.2.3. add tiles, map array
3.2.2.4. add scrollbars
3.2.2.5. add masks
3.2.2.6. add btnArray
3.3. edit map
3.4. scroll map
3.4.1. scroll map: y-direction
3.4.2. scroll map: x-direction
3.5. trace array
*/
//1. variables
var tile_size = 20;
var totalTiles:int = currentTile_mc.totalFrames;
var currentTile:int = 0;
var map:Array = new Array();
//Sprites, Movieclips (+Positions)
var selection_container:Sprite;
var t:Tile;
var map_height;
var map_width;
var level_container:Sprite;
var level_container_xPos = 65;
var level_container_yPos = 60;
var map_sprite_height:int = 0;
var map_sprite_width:int = 0;
var maskedView_map:Map_Maske;
var map_mask_height:int = 340;
var map_mask_width:int = 400;
var scroll_y_container:Sprite;
var scroll_y_container_yPos = 60;
var scrolltrack_y:Scrolltrack_y;
var scrollhead_y:Scrollhead_y;
var scroll_x_container:Sprite;
var scroll_x_container_xPos = 65;
var scrolltrack_x:Scrolltrack_x;
var scrollhead_x:Scrollhead_x;
var raster_x_container:Sprite;
var raster_x_container_xPos = 60;
var maskedView_raster_x:Raster_x_Maske;
var raster_y_container:Sprite;
var raster_y_container_yPos = 60;
var maskedView_raster_y:Raster_y_Maske;
var btnArray:ArrayButton;
var mapString:String = "";
//TextFormat
var format:TextFormat = new TextFormat();
format.size = 10;
format.align = TextFormatAlign.CENTER;
//2.UI
//2.1. map: height+width options, generate button
height_mc.height_txt.restrict = "0-9";
width_mc.width_txt.restrict = "0-9";
btnGenerate.addEventListener(MouseEvent.MOUSE_DOWN, generateMap);
//2.2. selectable tiles
selection_container = new Sprite();
selection_container.x = 10;
selection_container.y = 80;
for (var i:int; i=0 && mouseY-scroll_y_container_yPos<=scrolltrack_y.height-scrollhead_y.height+scrollhead_y.height/2) {
scrollhead_y.y = mouseY-scroll_y_container_yPos-scrollhead_y.height/2;
}
else {
if (mouseY-scroll_y_container_yPos-scrollhead_y.height/2<0) {
scrollhead_y.y = 0;
}
else {
scrollhead_y.y = scrolltrack_y.height-scrollhead_y.height;
}
}
if (map_sprite_height <= map_mask_height) {
level_container.y = level_container_yPos;
raster_y_container.y = raster_y_container_yPos;
}
else {
level_container.y = level_container_yPos-(map_sprite_height-scrolltrack_y.height)*scrollhead_y.y/(scrolltrack_y.height-scrollhead_y.height);
maskedView_map.y =(map_sprite_height-scrolltrack_y.height)*scrollhead_y.y/(scrolltrack_y.height-scrollhead_y.height);
raster_y_container.y = raster_y_container_yPos-(map_sprite_height-scrolltrack_y.height)*scrollhead_y.y/(scrolltrack_y.height-scrollhead_y.height);
maskedView_raster_y.y =(map_sprite_height-scrolltrack_y.height)*scrollhead_y.y/(scrolltrack_y.height-scrollhead_y.height);
}
}
//3.4.2. scroll map: x-direction
function scroll_map_x_start(event:MouseEvent):void {
scrollhead_x.removeEventListener(MouseEvent.MOUSE_DOWN, scroll_map_x_start);
stage.addEventListener(MouseEvent.MOUSE_MOVE, scroll_x);
stage.addEventListener(MouseEvent.MOUSE_UP, scroll_map_x_stop);
}
function scroll_map_x_stop(event:MouseEvent):void {
scrollhead_x.addEventListener(MouseEvent.MOUSE_DOWN, scroll_map_x_start);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, scroll_x);
stage.removeEventListener(MouseEvent.MOUSE_UP, scroll_map_x_stop);
}
function scroll_x(event:MouseEvent):void {
if (mouseX-scroll_x_container_xPos-scrollhead_x.width/2>=0 && mouseX-scroll_x_container_xPos<=scrolltrack_x.width-scrollhead_x.width+scrollhead_x.width/2) {
scrollhead_x.x = mouseX-scroll_x_container_xPos-scrollhead_x.width/2;
}
else {
if (mouseX-scroll_x_container_xPos-scrollhead_x.width/2<0) {
scrollhead_x.x = 0;
}
else {
scrollhead_x.x = scrolltrack_x.width-scrollhead_x.width;
}
}
if (map_sprite_width <= map_mask_width) {
level_container.x = level_container_xPos;
raster_x_container.x = raster_x_container_xPos;
}
else {
level_container.x = level_container_xPos-(map_sprite_width-scrolltrack_x.width)*scrollhead_x.x/(scrolltrack_x.width-scrollhead_x.width);
maskedView_map.x =(map_sprite_width-scrolltrack_x.width)*scrollhead_x.x/(scrolltrack_x.width-scrollhead_x.width);
raster_x_container.x = raster_x_container_xPos-(map_sprite_width-scrolltrack_x.width)*scrollhead_x.x/(scrolltrack_x.width-scrollhead_x.width);
maskedView_raster_x.x =(map_sprite_width-scrolltrack_x.width)*scrollhead_x.x/(scrolltrack_x.width-scrollhead_x.width);
}
}
//3.5. trace array
function traceArray(evt:MouseEvent):void {
mapString = "";
for (var i:int; i
And this is the result:
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.