stripped down example:
as player walks threw the level, new terrain is added.
function init()
{
//terrain pieces
var tiles:Array= new Array();
tiles.push(new piece1()); // each of these extend movieclip;
tiles.push(new piece2());
tiles.push(new piece3());
tiles.push(new piece4());
tiles.push(new piece5());
//terrain layout
var level:Array = new Array(1,4,3,1,2,1,5,2,1,2,4,3,1,2,1,5,2,1,2,4,3,1,2,1,5,2,1,2,4,3);
}
function enterFrameHandler(e:Event)
{
// example: grabbing a new tile
if (condition)
{
currentSlot += 1;
var tileType:uint = level[currentSlot];
addChild(tiles[tileType]);
}
}
This next example is more like how i currently have my game structured.
function init()
{
//terrain pieces
var tiles:Array= new Array();
tiles.push(new piece1()); // each of these extend movieclip;
tiles.push(new piece2());
tiles.push(new piece3());
tiles.push(new piece4());
tiles.push(new piece5());
//terrain layout
var level:Array = new Array(1,4,3,1,2,1,5,2,1,2,4,3,1,2,1,5,2,1,2,4,3,1,2,1,5,2,1,2,4,3);
var finalArray:Array= new Array();
//populate finalArray with references to the tiles, in order of appearance
for (var i:uint=0; i<level.length; i++)
{
var num:uint = level*;
finalArray.push(tiles[num]);
}
}
function enterFrameHandler(e:Event)
{
// example: grabbing a new tile
if (condition)
{
currentSlot += 1;
addChild(finalArray[currentSlot]);
}
}
I end up with ‘finalArray’ having multiple references to the same objects, but in proper sequence.
The idea in method2 was during game play i only need to access an array once per added tile, (as apposed to 2x in example one).
So the comparison is
Method1 has an extra call to an array ,per new tile (i supposed its not going to break my game)
Method2 has ‘finalArray’ populated with many duplicate references to display objects
Really my question is, what are the problems associated with having a lot of references in the swf? Is it bloatfull to have this array hold a ton of duplicate references back to the same few display objects? (I feel like it is)
The only reason i wouldn’t just use method one is i have read many times,<cough> rumblesushi</cough> on how you want to cut down on array access as much as possible, unlisted in the example is removeChild, i used use the same, so now 2 calls becomes 4 calls per new piece
thanks