|
-
Tonypa's old AS2 tile based tutorials...
I've been reading Tonypa's old AS2 tile based tutorials and while I'm very slowly getting a grasp on them, there's a small bit, that no matter how much I reread the tutorial, I can't wrap my head around it and was hoping for some clarification on the forums here. His code for building the maps are as follows:
Actionscript Code:
// our map is 2-dimensional array myMap = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1]]; // declare game object that holds info game = {tileW:30, tileH:30}; // walkable tile game.Tile0 = function () { }; game.Tile0.prototype.walkable = true; game.Tile0.prototype.frame = 1; // wall tile game.Tile1 = function () { }; game.Tile1.prototype.walkable = false; game.Tile1.prototype.frame = 2; // building the world function buildMap(map) { // attach empty mc to hold all the tiles and char _root.attachMovie("empty", "tiles", ++d); // declare clip in the game object game.clip = _root.tiles; // get map dimensions var mapWidth = map[0].length; var mapHeight = map.length; // loop to place tiles on stage for (var i = 0; i<mapHeight; ++i) { for (var j = 0; j<mapWidth; ++j) { // name of new tile var name = "t_"+i+"_"+j; // make new tile object in the game game[name] = new game["Tile"+map[i][j]](); // attach tile mc and place it game.clip.attachMovie("tile", name, i*100+j*2); game.clip[name]._x = (j*game.tileW); game.clip[name]._y = (i*game.tileH); // send tile mc to correct frame game.clip[name].gotoAndStop(game[name].frame); } } } // make the map buildMap(myMap); stop();
Oddly, after alot of uneducated study, I'm getting a handle on it....except this line
Actionscript Code:
game[name] = new game["Tile"+map[i][j]]();
I get that it's creating an object for each tile and referencing back to it via the "Tile"+map[i[[j] part, but I don't understand the 1st part: game [name].
I see this syntax alot in Tonypa's tutorials, but I'm not sure what's going on there. [] are for arrays, correct? By putting game[name], is this line putting the new tile objects into a new array? I've looked in alot of array tutorials as well as object tutorials, but I have yet to see any syntax for:
something [something] = something
I imagine it's establishing a variable, though I usually see var something = something. I guess ultimately, it's the [] brackets BEFORE the = sign that is confusing. Sorry for the VERY simple question, but thank you for any help guys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|