A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: tilebased help?

  1. #1
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693

    tilebased help?

    Alright I'm trying to make somewhat of a tilebased game... Really more so a learning experience and a way to experiment. The way I learn languages is by setting a goal and then just diving in and learning what I need as I go along and following tutorials. My acitonscript knowledge is limited and blurly, I have been messing around with actionscript for a few years but very on-and-off... I made the website www.hrprivacy.com which I'm not too proud of but has some reasonably intricate code, or at least I think so. ANYWAYS, assuming I'm not asking too much I am using tonypa's website (http://www.tonypa.pri.ee/tbw) as a tutorial and I like it very much but some of his explanations don't exactly cut it especially since there is no dialog. The following code I understand completely:

    Code:
    // our map is 2-dimensional array
    myMap = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 
    		 [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
    		 [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
    		 [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
    		 [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
    		 [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]];
    // declare game object that holds info
    game = {tileW:20, tileH:20};
    // 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;
    now I start to lose it in this next section:

    Code:
    // building the world
    function buildMap(map) {
    i don't understand where this term map comes in...

    edit: i figured out the whole map thingy xD
    Code:
    	// attach empty mc to hold all the tiles and char
    	_root.attachMovie("empty", "tiles", ++d);
    This makes sense except the ++d, i'm guessing it has something to do with how many tiles to make?

    Code:
    	// declare clip in the game object
    	game.clip = _root.tiles;
    makes sense

    Code:
    	// get map dimensions
    	var mapWidth = map[0].length;
    	var mapHeight = map.length;
    im confused about what map[0].length value would be equal to and map.length, im not sure where those come from...

    the rest of the lines are the following but I guess the above is enough to try and understand for now...
    Code:
    	// 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();
    i hope i'm not asking too much even though this post is pretty long... I'm just trying to make sense of some of this code... thanks in advance ^^
    Last edited by ChaseNYC; 08-08-2005 at 07:43 PM.
    mmm signature

  2. #2
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,180
    Aight,
    buildmap(map){
    }
    Is a function with a so called argument, it creates a variable map inside the function.
    Now if you call the function: buildmap(Spain), the variable map inside the function will have the same value as Spain. So in this case, it just copies myMap to map.

    About the ++d part; d is a variable, standing for depth. The ++ add's 1 to the variable every time it get's called. This will give the attached MC a unqie depth.

    The map[0] part:
    You're using a 2-dimensional array, like this: var map = [["a","b"],["c","d"],["e","f"]];

    Now, if you trace: map[0] It'll trace a,b. So that means it only traces the first 'block'. The length of the block is 2, because it contains only 2 values. Now if you look at your map array, the first block is the same as the width of your map (hence the variable name width when getting the value map[0].length); Now for the height, when you use: map.length It'll get the amount of 'blocks' inside the array; thus the height of the map.

    Hope this makes it clear

  3. #3
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693
    so this would mean the map.length(height) would return 6 and map[0].length would return 11 as it is how many blocks wide the map is?
    mmm signature

  4. #4
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693
    god damn i might kill myself... can some tell me why tut06.fla works and myMap.fla doesnt? this is driving me crazy!
    mmm signature

  5. #5
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693
    after comparing the two for like two hours i figured out the problem was that mine is published for flash player 7 while the tutorial is for flash player 5... I changed the publish settings on mine to player 5 and it works... so how do i change/fix the code so it works on flash player 7 or does it even matter???
    mmm signature

  6. #6
    hmm Pugger's Avatar
    Join Date
    Sep 2003
    Location
    Perth, Australia
    Posts
    616
    If you see a coloured variable, it is proabably a reserved varaible or function under flash player 7. Flash 7 has new functions with new names. Tonypa might have a function or variable with the same name as one of these reserved variables. You have to change their names if you want it to work with flash 7.

    Luckily flash highlights the reserved variables blue (unless you have changed the colour), so you know which ones belong to flash and which are user created.

    You can chick if it is being use right by highlighting it and right clicking. Select help. Then see if the variable being passed to it are being used in the way help describes.

    Doing this might get it to work.

  7. #7
    Senior Member
    Join Date
    Jun 2001
    Posts
    290
    Ive had similar issues w/ a couple of Tony's tutes as well...and that is definitely due to the flash 7/flash 5 change......it probably is a variable that needs to be set to "zero" when defined/created....flash 7 is very picky about things like that, but flash 5 and 6 are much more leneant ...so they would assume a var is zero if it doesn't have a specific value defined.....

    I remember running into the same issue/s.....but can't remember which var was....
    hope at least this sets you in the right direction.

    paul.

  8. #8
    hmm Pugger's Avatar
    Join Date
    Sep 2003
    Location
    Perth, Australia
    Posts
    616
    Found out it is case-sensitive as well.

  9. #9
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Quote Originally Posted by pentru
    Ive had similar issues w/ a couple of Tony's tutes as well...and that is definitely due to the flash 7/flash 5 change......it probably is a variable that needs to be set to "zero" when defined/created....flash 7 is very picky about things like that, but flash 5 and 6 are much more leneant ...so they would assume a var is zero if it doesn't have a specific value defined.....
    Thats true.

    Sometimes Flash7 also returns NAN (not a number) when same code gives 0 in Flash5.

    Quote Originally Posted by Pugger
    Found out it is case-sensitive as well.
    Thats true also.

    I might have used variables with different capitalization sometimes as the tutorials have been written over the years. And Flash5 doesnt care if you use mapW, mapw, MAPW or mApW.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center