I have quite alots of display objects to manage during runtime, so Im currently using Arrays to manage them. But the problem is I have few many types of displays objects(eg. Tile, Npc and Building) which are basically MovieClips linked to the library. Each display object plays different role where it will be checked on enter frame, a loop.
Method 2 sounds much more faster and extensible however Im worried if it would affect the checking rate of each display object during runtime as the displays:Array grow larger and probably making it glitchy
So which one of the following method is faster+less glitchy and explain why you choose it.
Thanks in advance.
Method 1
var tiles:Array = new Array()
var npcs:Array = new Array()
var buildings:Array = new Array()
function createTiles(){
for(var i:Number=0; i<10; i++){
var t:Tile = new Tile() //Display object in the library
t.x = i * 50
t.y = i * 50
addChild(t)
tiles.push(t)
}
}
function createNpcs(){...}
function createBuildings(){...}
addEventListener(Event.ENTER_FRAME, loop)
function loop(e:Event){
for(var i:Number=0; i<tiles.length; i++){
//some codes
}
for(var j:Number=0; j<npcs.length; j++){
//some codes
}
for(var k:Number=0; k<buildings.length; k++){
//some codes
}
}
Method 2
var displays:Array = new Array();
function createDispalys(){
for(var i:Number=0; i<10; i++){
var t:Tile = new Tile() //Display object in the library
t.x = i * 50
t.y = i * 50
addChild(t)
displays.push(t)
}
for(var j:Number=0; j<10; j++){
//some code
displays.push(t)
}
for(var k:Number=0;k<10; k++){
//some codes
displays.push(t)
}
}
addEventListener(Event.ENTER_FRAME, loop)
function loop(e:Event){
for(var i:Number=0; i<display.length; i++){
if(display[i] is Tile){
//some codes
}else if(display[i] is Npc){
//some codes
}else if(display[i] is Building){
//some codes
}
}
}