The one AS thread to rule them all, AS: Main
This is 1/3 tile based tutorials,
Introduction-drawing the map
Advanced Uses- "hitTests" and movement
Isometrical Tile Based Games
What is this about
This tutorial is about Tile Based programming, it presumes knowledge of Arrays and is not that easy. However tile based programming is very useful, when compared to hitTest on maps the tile based check took 1/10 the time to accomplish, and it only occurs when the player moves.
What are tiles?
Tiles are basically costume made squares, instead of using flash's X,Y coordinate system you place object on tiles.
The first stage
the first stage is to actually create your level appearance, you need to decide how big your level is, I will use 10*10 here but you should use as much as you need,just remmember, in tile based programming the level generation itself takes time. I always name my objects levelN, like level1, level2, level3 and so on, tile based games work perfectly with xml for dynamic maps.
let's create an empty level 1, each level has 3 main elements (and a fourth one (hit area I rather not discuss yet), terrain (meaning the land) objects (meaning the trees, and impassable stuff) and enemies (meaning moving objects)
first let's create the terrain
level1.terrain=new Array(new Array(0,0,0,0,0,0,0,0,0,0),
new Array(0,0,0,0,0,0,0,0,0,0),
new Array(0,0,0,0,0,0,0,0,0,0),
new Array(0,0,0,0,0,0,0,0,0,0),
new Array(0,0,0,0,0,0,0,0,0,0),
new Array(0,0,0,0,0,0,0,0,0,0),
new Array(0,0,0,0,0,0,0,0,0,0),
new Array(0,0,0,0,0,0,0,0,0,0),
new Array(0,0,0,0,0,0,0,0,0,0),
new Array(0,0,0,0,0,0,0,0,0,0));
this is the terrain, right now empty, we repeat the same process with objects and enemies, now remmember 0 means empty, the numbers really mean WHAT YOU TELL THEM TO, let's show how,
create a new movieclip and linkage-name it "tile-m" on it's first frame draw a 30*30 scale grass, on it's second 30*30 ice, these are your two tiles for now
create another one and linkage-name it "tile-0" for now it'll also have 2 frames. the first one will be empty and draw a rock in the second one.
now 0 represents grass (on the terrain map) and 1 represents ice, if there was a third frame 2 would represent whatever you draw in it.
now we need to actually create the map, this is done by a nested loop:
if(_root.map==null){ _root.createEmptyMovieClip("map");}
for(i=0;i<10;i++){
for(j=0;j<10;j++){
_root.map.attachMovie("tile-m","tile"+i+"_"+j,i*30+j*3000);//the depth doesn't matter here
_root.map.attachMovie("tile-m","tilem"+i+"_"+j,i*30+j*3000);//the depth does matter here
_root.map["tilem"+i+"_"+j].swapDepths(this._y);//so objects don't override.
_root.map["tile"+i+"_"+j]._x=i*30;//since 30 is the width/height
_root.map["tile"+i+"_"+j]._y=j*30;
_root.map["tilem"+i+"_"+j]._x=i*30;
_root.map["tilem"+i+"_"+j]._y=j*30;
}
}
there you have created a map based on the 2d array ;) congrats, about actually using it, on the next chapter, ask any questions on the tutorial here