Basic level editor for a tile based game
I am sharing with you a basic level editor made for the platform engine but easily adaptable to any tile based game made by Daniel Felipe Rodriguez
Your recent set of tutorials about the platform engine inspired me so I decide to contribute to your cause, I made a really really basic level editor but I’m sure it will help the level design, and maybe some future projects because the editor can be adapted really easy to any game.
In a future I will do a better editor, but this was just a quickly one, because really love this tutorials, continue with the good work!
The editor is made in AS3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | var currentTile:int = 0;
var horizontalTiles:int = 20;
var verticalTiles:int = 10;
var totalTiles:int = mcCurrentTile.totalFrames;
var levelTilesContainer:Sprite = new Sprite();
makeSelectionTiles();
makeLevelTiles();
function makeSelectionTiles():void {
var container:Sprite = new Sprite();
container.x = 200;
container.y = 20;
for (var i:int; i<totalTiles; i++) {
var tile:Tile = new Tile();
tile.gotoAndStop(i + 1);
container.addChild(tile);
tile.x = (tile.width - 1) * i;
tile.addEventListener(MouseEvent.MOUSE_DOWN, selectionClick);
}
addChild(container);
}
function selectionClick(evt:MouseEvent):void {
currentTile = evt.currentTarget.currentFrame;
updateCurrentTile();
}
function updateCurrentTile():void {
mcCurrentTile.gotoAndStop(currentTile);
}
function makeLevelTiles():void {
var xPos:Number = 0;
var yPos:Number = 0;
for (var i:int=0; i<verticalTiles; i++) {
for (var j:int=0; j<horizontalTiles; j++) {
var tile:Tile = new Tile();
tile.x = xPos;
tile.y = yPos;
tile.name = "" + i + j;
tile.addEventListener(MouseEvent.MOUSE_DOWN, levelClick);
levelTilesContainer.addChild(tile);
xPos += (tile.width - 1);
}
yPos += (tile.height - 1);
xPos = 0;
}
levelTilesContainer.x = 50;
levelTilesContainer.y = 100;
addChild(levelTilesContainer);
}
function levelClick(evt:MouseEvent):void {
evt.currentTarget.gotoAndStop(currentTile);
}
btnGenerate.addEventListener(MouseEvent.MOUSE_DOWN, generateClick);
function generateClick(evt:MouseEvent):void {
var array:String = "[ ";
for (var i:int=0; i<verticalTiles; i++) {
array += "[";
for (var j:int=0; j<horizontalTiles; j++) {
var target:DisplayObject = levelTilesContainer.getChildByName("" + i + j);
if (j == (horizontalTiles - 1)) {
array += (MovieClip(target).currentFrame - 1);
} else {
array += (MovieClip(target).currentFrame - 1) + ", ";
}
}
if (i == (verticalTiles - 1)) {
array += "] ]";
} else {
array += "],\n";
}
}
trace(array);
} |
And this is the result: once you click on “Generate” the script will trace the array.
For this reason there is no way to see the result online, you have to download the source and execute it inside Flash.
They can be easily customized to meet the unique requirements of your project.















(20 votes, average: 4.65 out of 5)









This post has 21 comments
Niall Lavigne
Wow, that looks pretty sweet, nice job Daniel. Now to learn AS3…
Andrius
Good. But I need AS2 version :)
Daniel
AS2 version will be easy to do with the as3, I love OOP(so hate as2) for this reason made it in as3, if I get some free time will make the as2. remember its a really! really!! really!!! basic editor, but if tou are in a hurry :-).
dix huit
Cool. Any news on the WordPress arcade plugin yet?
Emanuele Feronato
still working on it…
Josh of Cubicle Ninjas
Both Emanuele and Daniel are kings among men. This made my day! :)
Gecko
Argh! DARN YOU AS3!
I can’t wait for the as2 version!
Javier Lázaro
AS2 version, please…
Jerry
I click on generate and nothing happens?
brart
Jerry, read the text under the editor
Arxanas
Wow, that’s really good! Can you convert it to AS2, though, because I really suck at AS3.
Could you also maybe explain how it works, in case we want to make our own custom level editors fitted to our own needs?
Also, to Daniel Felipe Rodriguez, whoever you may be, you might want to add a legend at the bottom of the legend editor. Awesome work!
Prankard
This editor only traces out the level array. Basically, the traced array should be the same for both versions of the engine (both AS2 and AS3).
But obviously you need flash 9 or greater to export AS3 (unless you have flash 8 with the beta AS3).
Just remove all the “level[0] = ” etc and replace it with:
level = *insert traced level here*
Daniel
@Prankard yes the editor make the array of arrays in one big array, and its the same in as2 and as3.
For the as2 fans I have develop an as2 version, can found it in the forums http://www.triquitips.com/viewtopic.php?f=23&t=641&p=4516
Enjoy.
Daniel Rodriguez
@Arxanas, well it works really good to be something I made really fast :-), just need to change the tile movieclip and add other keyframes, I copy the emanuele movieclip tile, for this reason have his tiles.
AS3 Tilegame Editor
[...] again from the blog of Emanuele Feronato I created a very nice editor in Flex for my tilegame. The original was only Flash, but I converted it to Flex (which I think is a lot easier to create such interface [...]
Aksel
Hey, what you could do, is to use System.setClipboard(array); instead of tracing the whole map. That would do so you can just get the map code directly to the “copy paste” thing.
Tile based game: Level Editor
[...] Can find more info in his post, here. [...]
Daniel Rodriguez
@Aksel Thanks, its done.
More updates in this new post.
http://tutorials.group84.com/2008/12/tile-based-game-level-editor.html
Daniel
Man! You take a rock of work down of my shoulders – thank you so much!
AS3 level editor : Emanuele Feronato
[...] 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 [...]
Jonathan
Darn AS3! C’mon AS2!!