Sign in to follow this  
Nicholas Kong

How to organize game objects using lists

Recommended Posts

Nicholas Kong    1535

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.   

Share this post


Link to post
Share on other sites
Squared'D    2427

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.

Share this post


Link to post
Share on other sites
Nicholas Kong    1535

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

Share this post


Link to post
Share on other sites
adam4813    729

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this