Infinite Arrays?

edited April 2014 in How To...

I want to create infinitely generating terrain for a program I'm making. I tested by adding and subtracting from the coordinates I gave the noise function, which worked out okay for making an infinite map you could travel on.

But what if I want to store the map inside of an array? You can't head west or north very long, because you'll walk right off the map and crash the program (since I was trying to access -1).

I've heard of something called ArrayList, but I'm not sure if that will solve my problem...

Thanks ahead of time for any answers! I appreciate how fast my last question was answered :)

Answers

  • Your first stop should be to check out the API for Processing, which contains a tutorial on how to use ArrayLists: http://www.processing.org/reference/ArrayList.html

    If you're still confused, I recommend a google search of "ArrayList" for more detail.

    But the gist is this: an ArrayList is like an array, except you can dynamically add objects to an ArrayList, and its capacity automatically increases.

    However, an ArrayList won't magically give you an infinite amount of memory or make integer overflow go away, so it won't actually give you infinite capacity. I suggest that most infinite terrain generators you've seen were doing something clever with procedural generation or loading.

  • thanks!

Sign In or Register to comment.