Not sure if this will help you much, because the bubbles are managed in a reeeeaaalll simple way, but anyway:
for (int i=0; i<NUMBER_OF_BOXES; i++) {
Object3D box=Primitives.getSphere(4,1);
box.calcTextureWrapSpherical();
box.setTexture("wood");
box.setTransparency(0);
box.setEnvmapped(Object3D.ENVMAP_ENABLED);
box.setCollisionMode(Object3D.COLLISION_CHECK_SELF);
box.setOrigin(new SimpleVector(140,0,-117));
setBox(box, i);
box.translate((float)Math.random()*-140, 0, (float) Math.random()*117);
theWorld.addObject(box);
boxes[i]=box;
}
And the code for setBox():
private void setBox(Object3D box, int i) {
float x=15f-30f*(float) Math.random();
float y=20f-40f*(float) Math.random();
float z=15f-30f*(float) Math.random();
box.setTranslationMatrix(new Matrix());
box.translate(new SimpleVector(x, y, z));
float trXn=1.5f+2f*(float) Math.random();
float trZn=1.1f+2f*(float) Math.random();
trX[i]=trXn/2f;
trZ[i]=trZn/2f;
lifeTime[i]=0;
box.rotateX(x);
box.rotateY(y);
box.rotateZ(z);
}
The bubbles are stored in the array named boxes (they were boxes in the first version... :wink: ) and their current translation in X and Z direction in trX and trZ. In addition, the lifetime of each bubble is stored in the lifeTime[]-array. But this is ugly code written to serve a single purpose. It would be better to wrap this information into an object (or maybe to extend Object3D, which sadly isn't possible in 0.97 but will be possible in 0.98 because i'll get rid of the useless final-stuff) and manage these objects by a simple Manager-class. If you don't want to write such a wrapper class and go with the array-approach, the Manager is still a good idea because it can hide this fact from the rest of the code.
Hope this helps.