Array editing in Android
Ive been working on an app for android much alike the program "Powder Toy". In order to simulate particle "stacking" I h开发者_运维技巧ave an array that monitors every column and if a particle goes past the value of the corresponding element, it is stopped and the element is increased for the next particle to land a little higher. When the element is changed it doesn't just change by one, instead I got numbers changing from, for example: 320 to -1211, 320 to -602, 320 to 14, and so on. I might be missing something basic about array editing, any ideas how to get around this?
for(int i = 0; i < intspan; i++){
tempx = particlex[i];
tempy = particley[i];
if(tempx == 0 && tempy == 0) {
return;
} else {
canvas.drawPoint(tempx, tempy, paint);
if(tempy < columns[tempx]) {
particley[i] += 1;
}
else if (tempy >= columns[tempx]){
columns[tempx]--;
}
}
}
In the part
else if (tempy >= columns[tempx]){
columns[tempx]--;
}
Your are decreasing columns[tempx], when it is smaller than tempy. Therefore it is getting smaller and smaller. And as it is inside a for loop, it could be decreased by up to the number of your particles in a single run.
精彩评论