Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm currently working on a Java game I know a lot of games created all instances of objects beforehand and then bring then in and out of play when they are needed.

Will it be worth it to have a Vector of all instances that are alive, and loop through that instance of going through all of the instances and checking the alive boolean?

Thanks

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

For simplicity, it's easier to have one vector/array that has all the objects that are alive. You don't want to check if they are alive in order to update them. That list represents the objects that need to be updated. Have a second vector/array, a stack if you will, that you add "dead" objects to once they are not needed for the time being. Once you need to reuse them simply pop them back into your vector that you're calling an update on.

If you're going by this approach might be interesting to read on object-pools

Of course you could also just remove them from memory and create new objects by instantiating them when needed. Eitherway, it's cleaner if you only hold your objects that actually need updating. All your objects that don't need to be updated( because they are inactive/dead) shouldn't be there.

share|improve this answer
    
The wiki link was very helpful, Thanks! –  Fricken Hamster Jan 22 '13 at 4:55
    
@FrickenHamster if you are satisfied with my answer, please accept it. So it can be closed. –  Sidar Mar 22 '13 at 16:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.