Created
February 15, 2012 12:47
-
-
Save grapefrukt/1835445 to your computer and use it in GitHub Desktop.
Ta bort döda GameObjects ur Vectorn samtidigt som update körs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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