A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Image Slicing and tile replacement

  1. #1
    Junior Member
    Join Date
    May 2008
    Posts
    4

    Image Slicing and tile replacement

    Hello all.
    I'm a bit of a weekend warrior when it comes to flash, so bear with me.
    Basically, I'm writing an application to be used for Dungeons and Dragons. The idea is to replace traditional battle-mats and markers with a laptop and projector. Now, to the problem.

    I'm using Filippo Lughi's method of slicing up a tileset image (http://www.flepstudio.org/forum/tuto...ipt-3-0-a.html -- great tutorial), placing individual tiles into an array, reading an array from a text file, then placing tiles from the tiles array on the stage corresponding the text file. Here's the troublesome bit of code.

    Code:
    var tilenum:int=0;
    	for (var k=0;k<currentMapArray.length;k++) {
    		for (var l=0;l<currentMapArray[k].length;l++) {
    			tilenum=currentMapArray[k][l];
    			var tileToAdd:MovieClip = new MovieClip();
    			tileToAdd = clips_array[tilenum];
    			addChild(tileToAdd);
    			tileToAdd.name = "tile-"+l+"-"+k;
    			tileToAdd.width=gridSize;
    			tileToAdd.height=gridSize;
    			tileToAdd.x = gridSize*l;
    			tileToAdd.y = gridSize*k;
    			trace(tileToAdd.name);
    			}
    	}
    When the code is run, all of the tile names are traced, but only two tiles end up on the stage. The two that make it onto the stage are the last instances of each type of tile (image attached). It seems like each run through the loop replaces the previously placed tile if it's the same type. Does anyone have an idea why this is happening? No errors are thrown during compiling. When I check Objects, there are only two tile clips listed-- the two on the stage.

    Any insight would be greatly appreciated. I can post the rest of the code if necessary. Thanks!
    -Hero
    Attached Images Attached Images

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    What kind of array is currentMapArray? Can you give some details of its content.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    May 2008
    Posts
    4
    The array currentMapArray is a normal 2-Dimensional array made up of integer numbers that correspond to tiles. Example content could be:

    0,0,0,0,0,0,0,0,0,0,0,0,0
    0,0,0,0,0,0,1,1,1,0,0,0,0
    0,0,0,0,0,0,1,1,1,0,0,0,0
    0,0,0,0,0,0,0,0,0,0,0,0,0
    0,0,0,0,0,0,0,0,0,0,0,0,0

    The zeros correspond to a particular tile, as do the ones. clips_array is the array that stores the individual sliced tiles from the original tileset image.

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    This is what disturbs me currentMapArray[k][l]. Have you traced tilenum?
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Junior Member
    Join Date
    May 2008
    Posts
    4
    Yeah, I've traced tilenum. It outputs the correct value for each point on the grid. currentMapArray is a nested array.

    Before I implemented the actual bitmap tiles, I was using dummy movieclips that were just black and white squares. Black was 0, white was 1. Everything worked fine there.

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Can you post the fla.
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Junior Member
    Join Date
    May 2008
    Posts
    4
    Here's an archive with all the resources. Try to ignore the terrible organization .
    Attached Files Attached Files

  8. #8
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    The distribution of the clips over the squares is ok. That is not the problem. You need to check if the MovieClips have images. It seems that is the problem.
    - The right of the People to create Flash movies shall not be infringed. -

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