2010-06-14 66 views
1

我剛剛在actionscript 3上試過我的手,並遇到了路障。 我該如何間歇地渲染立方體(cube1),即。交錯加載。我需要立方體彼此分開加載。對象間歇/交錯加載

下面是我到目前爲止的代碼段:

var rows:int = 5; 
var cols:int = 3; 
var spacery:int = 100; 
var spacerx:int = 120; 
var box_count:int = 8; 

for(var i:int; i < box_count; i++) {            
    cube1 = new Cube(ml,100,10,80,1,1,1);    
    cube1.y = ((i % rows)) * (cube1.x + spacery); 
    cube1.x = Math.floor(i/rows) * (cube1.x +spacerx); 
    cube1.z = 0; 

    bigBox.addChild(cube1); 
} 
+0

你嘗試過一個計時器? – phwd 2010-06-14 13:27:59

回答

2
//Create an array out side the function; as a global (instance) variable: 
var cubes:Array = []; 

//instead of bigBox.addChild(cube1), store them in the array: 
cubes.push(cube1); 

//initialize a timer outside after for loop 
//Fire every 100 milliseconds, box_count times 
var timer:Timer = new Timer(100, box_count); 
timer.addEventListener(TimerEvent.TIMER, onTick); 
timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTickDone); 

function onTick(e:Event):void 
{ 
    bigBox.addChild(cubes[timer.currentCount]); 
} 
function onTickDone(e:Event):void 
{ 
    cubes = null; 
    timer.removeEventListener(TimerEvent.TIMER, onTick); 
    timer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTickDone); 
    timer = null; 
}