A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Using arrays to make a map of images

  1. #1
    Junior Member
    Join Date
    Jun 2008
    Posts
    2

    Question [resolved]Using arrays to make a map of images

    I'm trying to make a game in Flash, and since users will be able to make their own levels in it, I thought I should make the levels of the game with actionscript. I think I approached it correctly by using arrays, but I'm having trouble turning that array into the map of the game. basically, I have one movie clip used as a base, with it's many frames being the different tiles. each entry in the multidimensional array is one character, and that character will tell what the tile (or the frame) should be.

    but I'm having trouble actually creating the map. I'm trying to use "for" to make a loop that will add each tile to the map using addChild. But I haven't seen anything that could tell me how to use "addChild" to add multiple instances of the SAME movie clip. so all of the tiles have the same name and the same properties, which means they also have the same coordinates. So any help?
    Last edited by Acceleron_3000; 06-23-2008 at 12:28 PM.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You cannot add the same instance multiple times. You CAN add multiple instances of the same library class. Let's say you've got a MovieClip in your library called Tiles which is the movie you described. You can do this to get two of them:
    Code:
    var firstTile:Tiles = new Tiles();
    //tell firstTile which frame to go to.
    firstTile.x = 0;
    firstTile.y = 0;
    addChild(firstTile);
    
    var secondTile:Tiles = new Tiles();
    //tell secondTile which frame to go to
    secondTile.x = 10;
    secondTile.y = 0;
    addChild(secondTile);
    You can generalize this to creating and placing a new Tiles instance within your for loop.

    Creating a new MovieClip for each tile in your game is a pretty heavyweight way of going about things. You might want to look into Bitmap and BitmapData, and simply draw each tile rather than creating a separate object for each.

  3. #3
    Junior Member
    Join Date
    Jun 2008
    Posts
    2
    actually, I have one movie clip, where each frame is a different tile. if using bitmapData is better than this approach, then I'll look into that. I think I understood what you meant, though.

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