Skip to content

Instantly share code, notes, and snippets.

@grapefrukt
Created February 15, 2012 12:47
Show Gist options
  • Save grapefrukt/1835445 to your computer and use it in GitHub Desktop.
Save grapefrukt/1835445 to your computer and use it in GitHub Desktop.
Ta bort döda GameObjects ur Vectorn samtidigt som update körs
public function update():void{
// loopa igenom hela vektorn, fast baklänges
for(var i:int = _collection.length - 1; i >= 0 ; i--){
// om vårt GameObject inte lever
if(_collection[i].isAlive == false){
// ta bort det som child
removeChild(_collection[i]);
// och slutligen ta bort ur vektorn
_collection.splice(i, 1);
// om det lever, kör update som vanligt
} else {
_collection[i].update();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment