We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello Community,
I work on a project where I need many arrays,and my questions are
1) Is it possible to store arrays of the same type (all integer arrays) in on array,something like
blockcontrol_alpha[]={blockcontrol_1,blockcontrol_2,blockcontrol_3....etc.}
In this case,blockcontrol_1 etc. are two dimensional arrays. I search for something like this because I need a performance saving way to store lots of data and I dont need more than 10 arrays at the same time for working. My game is divided in areas of 240x360 px and I only have to load the arrays you are possible to see.
2) Is there a way to declare new arrays while the game is running? At the beginning there are 60 integer arrays with a defined number of 150 fields for each array. At the moment where the player would came closer to the end of the map I have to declare new arrays.
Maybe are my questions are little bit confusing but I hope you understand what I mean.
greetz Flozzel
Answers
You can also use 3D arrays to hold the data
Don't think you can declare them later but you could overwrite the old data
You can increase mem in the prefs...
Did you have difficulties? Try load everything in setup() first.
Hi Flozzel,
yes arrays can have any dimension (usually 3 dimensions is the maximum you need, else you should think of a different datastructure) so this is an example of 2dimensional arrays:
hope that helps
Thanks this is very helpfull. Maybe this is a way to get my problem solved. I have to rethink my way of programming,dont think its the right way like that.
greetz Flozzel
Edit: This is a little bit confusing :)
Can you give me an example for an two dimensional array with 5 fields? For example this values would be stored in one array matrix:
blockcontrol_1[0][0]=240; blockcontrol_1[0][1]=360; blockcontrol_1[0][2]=2; blockcontrol_1[0][3]=1; blockcontrol_1[0][4]=0;
blockcontrol_1[1][0]=264; blockcontrol_1[1][1]=360; blockcontrol_1[1][2]=3; blockcontrol_1[1][3]=1; blockcontrol_1[1][4]=0;
blockcontrol_1[2][0]=1200; blockcontrol_1[2][1]=360; blockcontrol_1[2][2]=2; blockcontrol_1[2][3]=1; blockcontrol_1[2][4]=0;
blockcontrol_1[3][0]=1224; blockcontrol_1[3][1]=360; blockcontrol_1[3][2]=3; blockcontrol_1[3][3]=1; blockcontrol_1[3][4]=0;
......
What would be my [x][y] for getting blockcontrol[2][1] in the case of an array like int[][] matrix = new int[4][4]; ?
greetz Flozzel
I don't get your question:
it would be matrix[2][1] - but what do you mean?
blockcontrol and matrix are both 2D arrays.
A 2D Array is like chessboard: you tell the row number and the column number and come to a cell with a value / number.
You can have a grid 5x5 or like chess 8x8 or 100x1000 - it stays 2D.
1D array is a simple list (only row numbers)
3D array - think of 8 boards of chess stacked one upon another - you tell the etage number, the row number and the column number and come to a cell with a value / number.
useful for a game like this:
http://www.tischlereihein.de/Bilder/Brettspiele/Anleitung/3D-Muehle.gif
this is a typical 2D array
Oh yes,of course I mean a 3d array.But I understanded it now,
"3D array - think of 8 boards of chess stacked one upon another - you tell the etage number, the row number and the column number and come to a cell with a value / number."
is an good example thanks. greetz Flozzel
this is a simple 3D array
the array holds rects/cubes of class Rect
it features a rotating camera