Wierd behavior with drawing
in
Programming Questions
•
1 year ago
Hi, I'm trying to draw instances that are stored in a 2d array at a certain depth so that objects at 50 depth are drawn before objects at lower depths (49 or smaller). And therefore the objects with depth 50 will be drawn behind objects at depth of 1. Now this works except that it only lets me set the first one and then all objects appear in at 0,0.
- int[][] Depth = new int[51][50];
int[] Depthcounter = new int[51];
int[][] World = new int[50][5];
int Objects = 1; - void setup() {
size(1000,1000);
for (int i = 0; i < 51; i++) {
Depthcounter[i] = 0;
}
} - void draw() {
for (int i= 50; i > 0; i--) {
for (int j= 0; j < Depthcounter[i]; j++) {
rect(World[Depthcounter[j]][1],World[Depthcounter[j]][2],50,50);
print(World[Depthcounter[j]][1]);
}
}
} - void mousePressed() {
World[Objects][0] = 1;
World[Objects][1] = mouseX;
World[Objects][2] = mouseY;
World[Objects][3] = 45;
Depth[1][Depthcounter[1]] = Objects;
Depthcounter[1] += 1;
Objects += 1;
}
Depth stores the depth Depth[actual depth from 0 to 50] and then the number of the instance thats in the array:
Depth[1][5] will retrieve the object that is at depth 1 and is at position 5 (the fifth object).
Depthcounter hold the numer of objects at a certain depth so Depthcounter[2] will retrieve the numer of objects at that depth.
Thanks in advance.
1