title: Libgdx how to create new objects of body to draw dynimcally
body: <p>I am trying to make a game where apples will fall from sky and allow boy to eat them
  I had already made the environment and the boy and one apple falling correctly
  but I want to make more objects of the apple to fall from sky at specific time
  how can I repeat the calling of apple class, where I have to call it 
  I built the apple body inside the apple class and use it inside the PlayScreen class and this is the code:
  Apple class: </p>
  
  <pre><code>public class Apple extends Sprite {
  
      public PlayScreen screen;
      public World world;
      public Apple apple;
      public Body b2body;
      public Vector2 velocity;
      public float counter;
      private TextureRegion Apple;
      //private Animation collectorRu;
      private float stateTimer;
      private boolean toDestroy;
      private boolean destroyed;
      public Apple(World world,PlayScreen screen)
      {
          super(screen.getAtlas().findRegion("boys3"));
          this.screen=screen;
          this.world=world;
          stateTimer=0;
          defineApple();
          Apple=new TextureRegion(getTexture(),0,0,120,120);
          setBounds(0, 0, 20 / Fruits.PPM, 20 / Fruits.PPM);//here we can change the size of our Animation
          setRegion(Apple);
          toDestroy=false;
          destroyed=false;
          velocity=new Vector2(0,-2);
          counter=0;
      }
      public void defineApple() {
          BodyDef bdef=new BodyDef();
  
          bdef.position.set(100/Fruits.PPM,200/Fruits.PPM);
          bdef.type=BodyDef.BodyType.DynamicBody;
          b2body=world.createBody(bdef);
          FixtureDef fdef=new FixtureDef();
          //PolygonShape shape=new PolygonShape();
          CircleShape shape=new CircleShape();
          shape.setRadius(7 / Fruits.PPM);
          fdef.filter.categoryBits=Fruits.APPLE_BIT;
          fdef.filter.maskBits=Fruits.GROUND_BIT | Fruits.COLLECTOR_BIT;
          fdef.shape=shape;
          b2body.createFixture(fdef).setUserData(this);
  
      }
      public void update(float dt)
      {
  
          stateTimer += dt;
          if(toDestroy&amp;&amp;!destroyed)
          {
              world.destroyBody(b2body);
              destroyed=true;
              stateTimer=0;
          }
          if(!destroyed) {
              b2body.setLinearVelocity(velocity);
              setPosition(b2body.getPosition().x - getWidth() / 2, b2body.getPosition().y - getHeight() / 2);
          }
  
  
      }
      public void draw(Batch batch)
      {
          if(!destroyed )
          {
              super.draw(batch);
          }
      }
      public void hit()
      {
          toDestroy=true;
  
      }
  
  }
  </code></pre>
  
  <p>the Playscreen class:</p>
  
  <pre><code>public class PlayScreen implements Screen {
      private Fruits game;
      private TextureAtlas atlas;
      private OrthographicCamera gamecam;
      private Viewport gameport;
      private Hud hud;
      private TmxMapLoader mapLoader;
      private TiledMap map;
      private OrthogonalTiledMapRenderer renderer;
      private World world;
      private Box2DDebugRenderer b2dr;
      private Collector player;
      private boolean right=true;
      private boolean left=true;
      private Apple apple;
      public float counter;
  
      private Controller controller;
  
  
      public PlayScreen(Fruits game)
      {
          this.game=game;
          gamecam=new OrthographicCamera();
          gameport=new FitViewport(Fruits.V_WIDTH/Fruits.PPM,Fruits.V_HIEGT/Fruits.PPM,gamecam);
          hud=new Hud(game.batch);
          atlas=new TextureAtlas("mypack.pack");
          mapLoader=new TmxMapLoader();
          map=mapLoader.load("level3.tmx");
          renderer=new OrthogonalTiledMapRenderer(map,1/Fruits.PPM);
          gamecam.position.set(gameport.getWorldWidth()/2,gameport.getWorldHeight()/2f,0);
  
          world=new World(new Vector2(0,-10),true);
          b2dr=new Box2DDebugRenderer();
          new B2WorldCreator(this);
          player=new Collector(world,this);
          world.setContactListener(new WorldContactListener());
          controller=new Controller(game.batch);
          apple=new Apple(world,this);
  
          counter=0;
  
      }
      @Override
      public void show() {
  
      }
  
      public TextureAtlas getAtlas()
      {
          return atlas;
      }
      public void handleinput(float dt)
      {
          if (controller.isRightPressed()&amp;&amp;player.b2body.getPosition().x&lt;3.7f)
          {
              if(right)
                  player.b2body.applyLinearImpulse(new Vector2(0.3f, 0), player.b2body.getWorldCenter(), true);
              else {
                  player.b2body.setLinearVelocity(0, 0);
                  right=true;
                  left=false;
              }
              //player.b2body.setTransform(player.b2body.getPosition().x+0.05f,player.b2body.getPosition().y,player.b2body.getAngle());
          }
          if (controller.isLeftPressed()&amp;&amp;player.b2body.getPosition().x&gt;0.26f ) {
              if(left)
                  player.b2body.applyLinearImpulse(new Vector2(-0.3f, 0), player.b2body.getWorldCenter(), true);//5
              else {
                  player.b2body.setLinearVelocity(0, 0);
                  right=false;
                  left=true;
              }
              //player.b2body.setTransform(player.b2body.getPosition().x - 0.05f, player.b2body.getPosition().y, player.b2body.getAngle());
          }
          if (controller.isUpPressed() &amp;&amp; player.b2body.getLinearVelocity().y == 0) {
  
              player.b2body.applyLinearImpulse(new Vector2(0, 4), player.b2body.getWorldCenter(), true);
  
          }
      }
      public void update(float dt)
      {
          handleinput(dt);
  
          world.step(1 / 60f, 6, 2);
          player.update(dt);
          apple.update(dt);
  
          gamecam.update();
          renderer.setView(gamecam);
      }
      public TiledMap getMap()//12 this is for Goomba
      {
          return map;
      }
      public World getWorld()
      {
          return world;
      }
  
      @Override
      public void render(float delta) {
          update(delta);
          Gdx.gl.glClearColor(0, 0, 0, 1);
          Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
          renderer.render();
          b2dr.render(world, gamecam.combined);
          game.batch.setProjectionMatrix(gamecam.combined);
          game.batch.begin();
          //Gdx.app.log("hi","hello");
          counter+=delta;
          player.draw(game.batch);
          apple.draw(game.batch);
  
          game.batch.end();
          game.batch.setProjectionMatrix(hud.stage.getCamera().combined);
          hud.stage.draw();
          controller.draw();
  
      }
  
      @Override
      public void resize(int width, int height) {
          gameport.update(width,height);
          controller.resize(width, height);
      }
  
      @Override
      public void pause() {
  
      }
  
      @Override
      public void resume() {
  
      }
  
      @Override
      public void hide() {
  
      }
  
      @Override
      public void dispose() {
          map.dispose();
          renderer.dispose();
          world.dispose();
          b2dr.dispose();
          hud.dispose();
      }
  }
  </code></pre>