• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Generating a lot of objects

Hello all! I'll try to be concise

I'm creating a 2d game and have run into another problem. I use array lists for generating everything that has multiple instances, background images, foreground images, enemies, etc. The problem I have is if I choose to generate any more than a certain number of any given object I get an arrayindexoutofboundsexception even though the code works fine with lower numbers. For the background images that are larger, the number seems to be lower (about 40). for enemies, which are smaller, the limit is more (about 150). Am I missing something? I don't believe I'm out of memory as I'm not getting that error. And I can't find any info that says there is a limit for arrays. I'm not sure what other info I can give other than the code in question
generation code
Y=0
last = 13
while (y < 116) {
Foreground foreground = new Foreground(last,0.7f);
foregrounds.add(foreground);
last = foreground.position.x + 26;
Y += 1;
}

Render Code
len = world.foregrounds.size();
for (int i = 0; i < len; i++)
Foreground foreground = world.foregrounds.get(i);
Batcher.drawsprite(foreground.position.x, etc. Etc.
}

The above codes work if the variable is lower. But sends the error as soon as it goes above a certain number.
 
Back
Top Bottom