Such a question, it is necessary to change the image of the sprite at the moment when the rectangel object is not in focus at the camera.
camera.setToOrtho(false, Drop.WIDTH, Drop.HEIGHT); camera.update(); I explain:
**OrthographicCamera camera;** //ΠΊΠ°ΠΌΠ΅ΡΠ° final static int MAX_SPRITES = 24; //ΡΠΏΡΠ°ΠΉΡΡ Ρ ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΠ΅ΠΌ Sprite bucketImage, background, r1, r2, r5, r10, r20, r50, r100, r200, r500, k1, k2, k5, k10, k20, k50, old100, old500, old1000, old5000, old10000, old20000, old50000, old100000, old200000; Sprite[] arraySprites; 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() { raindrop = new Rectangle(); raindrop.x = MathUtils.random(0, (Drop.WIDTH) - 100);//800 -100 raindrop.y = Drop.WIDTH + 100; //Ρ.Π΅ 800 +100,ΡΡΠΎ Π±Ρ ΠΎΠ±ΡΠ΅ΠΊΡ ΠΈΠ·ΠΌΠ΅Π½ΡΠ» ΡΠΏΡΠ°ΠΉΡ Π²Π½Π΅ ΠΊΠ°ΠΌΠ΅ΡΡ raindrop.width = 100; raindrop.height = 100; raindrops.add(raindrop); lastDropTime = TimeUtils.nanoTime(); } I change the sprites in the timer as follows:
public void timerSpriteChange() { Timer timer = new Timer(); timer.schedule(new Timer.Task() { @Override public void run() { index = ((int) ((Math.random() * MAX_SPRITES))); } }, 1, 5); } I do everything in the timer, because I do not know how to implement with the camera ...
and the method call itself
if (TimeUtils.nanoTime() - lastDropTime > 1000000000) { spawnRaindrop(); }