Hello! I want the snow to fall while one snowflake falls.

public Scene onLoadScene() { // Таймер myTimer = new Timer();myTimer.schedule(new TimerTask() { @Override public void run() { TimerMethod(); } }, 0, 1000); // Снежинка Random randomGenerator = new Random(); Random randomGeneratorXshift = new Random(); pX = randomGenerator.nextInt(CAMERA_WIDTH); // Снежинка создается в координате (Х) любое значение в пределах ширины камеры shiftX = randomGeneratorXshift.nextInt(100) - 50; AnimatedSprite snow = new AnimatedSprite (pX, 1, this.mTextureSnowRegion); final PhysicsHandler physicsHandler = new PhysicsHandler(snow); snow.registerUpdateHandler(physicsHandler); physicsHandler.setVelocity(shiftX, DEMO_VELOCITY); scene.getLastChild().attachChild(snow); return scene; } private void TimerMethod() { //This method is called directly by the timer //and runs in the same thread as the timer. //We call the method that will work with the UI //through the runOnUiThread method. this.runOnUiThread(Timer_Tick); } private Runnable Timer_Tick = new Runnable() { public void run() { //This method runs in the same thread as the UI. //Do something to the UI thread here } }; 

Where and how should I insert the snowflake generation code to make the timer work?

    1 answer 1

    So you create only one snowflake. Code

     shiftX = randomGeneratorXshift.nextInt(100) - 50; AnimatedSprite snow = new AnimatedSprite (pX, 1, this.mTextureSnowRegion); final PhysicsHandler physicsHandler = new PhysicsHandler(snow); snow.registerUpdateHandler(physicsHandler); physicsHandler.setVelocity(shiftX, DEMO_VELOCITY); scene.getLastChild().attachChild(snow); 

    need to call several times in a loop.