When creating an object in a random order, it is also necessary to draw a sprite for this object. final static int MAX_SPRITES = 15; //constant. spriteIndex ++; // turn to next. sprite. Array of objects (drops):
**Array<Rectangle> raindrops = new Array<Rectangle>();** To facilitate the creation of raindrops, there is a method called spawnRaindrop (), which creates a new rectangle, sets it in a random position on the upper edge of the screen and adds it to the array with raindrops.
private void spawnRaindrop() { Rectangle raindrop = new Rectangle(); raindrop.x = MathUtils.random(0, 800 - 100); raindrop.y = 480; raindrop.width = 120; raindrop.height = 120; raindrops.add(raindrop); lastDropTime = TimeUtils.nanoTime(); } on the stage I draw like this:
for (Rectangle raindrop : raindrops) { game.batch.draw(arraySprites[spriteIndex], raindrop.x, raindrop.y); spriteIndex++; if (spriteIndex > MAX_SPRITES - 1) spriteIndex = 0; } arraySprites = new Sprite[15]; array of sprites from 15 different sprites, initialized in this form
r1 = new Sprite(atlas.findRegion("r1")); r1.flip(false, true); and so 15 pieces.
Problem: the first element of the array was created and a sprite was drawn from the array of sprites in random order. In fact, it turns out that all the sprites are stupidly drawn in a circle for one drop. THAT NEEDS FOR EVERY NEW RECTANGLE OF A RAINDROP TO SUBJECT A RANDOM SPRAY FROM THE ARRAY OF SPRAYS 