View Single Post
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator 17 Creative Assets 2005-09-07 #13 Old  
Yep, creating a tiled background is quite easy, but to be honest using a 4x4 tile probably isn't the best thing to use because it's too small.

With Flash 8 you could simply create a bitmap image within Flash and flood-fill it with your tile... nice easy and quick. With Flash 7 (and lower) you need to create a new movieclip for each tile, and with a 4x4 tile that's going to kill Flash... a 600 x 400 sized stage for example would require 15000 movieclips (nooooooooooooooo!).

If you used a larger tile though (50x50 etc) then it should be ok. Anyway, here's a little function that you can use to create a tiled background.

ActionScript Code:
  1. function createBackground(targetMC:MovieClip, tileID:String):Void {
  2.     // create a temp mc to get the tile size
  3.     targetMC.attachMovie(tileID, "temp", 0);
  4.     var tW:Number = targetMC.temp._width;
  5.     var tH:Number = targetMC.temp._height;
  6.     targetMC.temp.removeMovieClip();
  7.     // work out how many tiles we need
  8.     var tX:Number = Math.ceil(Stage.width / tW);
  9.     var tY:Number = Math.ceil(Stage.height / tH);
  10.     // build the tiles
  11.     var i:Number = 0;
  12.     for(var x:Number = 0; x < tX; x++) {
  13.         for(var y:Number = 0; y < tY; y++) {
  14.             var mc:MovieClip = targetMC.attachMovie(tileID, "tile" + i, i);
  15.             mc._x = tW * x;
  16.             mc._y = tH * y;
  17.             i ++;
  18.         }
  19.     }
  20. };
  21.  
  22. // example usage
  23.  
  24. createBackground(myBackground_mc, "bricks");
targetMC is the movieclip that you want the tiles to be copied to (this could be _root if you want). tileID is the linkage name of the tile movieclip in your library. You need to have the tile in the library (a movieclip linked to the first frame of the movie).

I've only just woken up but I think that should work. If you have any problems with it just let me know.
Reply With Quote