How to organize game objects using lists

Started by
2 comments, last by adam4813 10 years, 11 months ago

Right now I have 3 arraylists in my game.

The responsibilities of the lists:

1)adding game objects and then empties itself

2)removing game objects and then empties itself

3)contains current objects that draws and updates

The issue I have some objects that draw and update that have collision detection and some do not have collision detection. Should I have an ArrayList specifically for those objects with collision and another for objects with no collision?

Is there any efficiency issues in terms of how many ArrayLists I should use? I am coding in Java.

Advertisement

Is there any efficiency issues in terms of how many ArrayLists I should use? I am
coding in Java.


I'm not going to comment on your design, just this question. If your arrays are just storing references, why can't you use multiple arrays if it helps you solve your problem. Even memory wise, an array of even 256 references is only 1kb. Speed and simplicity are probably important to you so use what works for your situation.

Learn all about my current projects and watch some of the game development videos that I've made.

Squared Programming Home

New Personal Journal

Is there any efficiency issues in terms of how many ArrayLists I should use? I am
coding in Java.


I'm not going to comment on your design, just this question. If your arrays are just storing references, why can't you use multiple arrays if it helps you solve your problem. Even memory wise, an array of even 256 references is only 1kb. Speed and simplicity are probably important to you so use what works for your situation.

Thanks

Maybe look at components? This would allow you to operate draw, update, and collision only on entities (objects in your case) that contain a corresponding component.

For an intro to Component Based Entity Systems check this article Understanding Component-Entity-Systems and also my article which describes how they fit into the Model, View, Controller paradigm: MVC and CBES as it Relates to Game Programming.

This topic is closed to new replies.

Advertisement