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 screen

  • And the rest are not drawn? Please clarify what does not work? - DimXenon
  • By the way, for sprites, you can use an array (or sheet) and generate them in a loop. - DimXenon
  • @ DimXenon added a screenshot to the topic. - upward
  • I will simply describe what I see. You create 15 sprites with the same range (atlas.findRegion ("r1") - this will be the same picture, if you do not change the name of the region - "r1"). Further, about the location of the sprite (s) - on the scene there are several sprites in different positions (judging by the picture - yes). If not, output the raindrop.x coordinates to the console. If yes, then apparently you do not like exactly what is used the same picture. To change the picture - change the name of the region - the used area of ​​the loaded image. Specify "r2", for example, instead of "r1". - DimXenon
  • Just make sure that all parameters are set for the new region "r2": borders, etc. - DimXenon

0