title: Image moving side to side
body: <p>My question is I'm creating a game where I have to get an image moving from one side of the screen to the other, and then coming back from the same side of the screen. For example I have an image of a jellyfish, it starts moving from the right side of the screen, to the left side, and then I want it to come back from the right side. I'm stuck and don't know what to do. I'm using LIBGDX and JAVA. </p>
  
  <pre><code>My code so far is :
  
  package gdx.game;
  
  import com.badlogic.gdx.ApplicationAdapter;
  import com.badlogic.gdx.Gdx;
  import com.badlogic.gdx.Input;
  import com.badlogic.gdx.graphics.GL20;
  import com.badlogic.gdx.graphics.Texture;
  import com.badlogic.gdx.graphics.g2d.Sprite;
  import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  import com.badlogic.gdx.math.MathUtils;
  import java.awt.Graphics;
  
  public class Main extends ApplicationAdapter {
      SpriteBatch batch;
      Texture img;
      Sprite sprite;
      float fGrav, fVelo, fX, fY;
  
  
      @Override
      public void create() {
          batch = new SpriteBatch();
          img = new Texture("JellyFish.png");
          sprite = new Sprite(img);
          sprite.setScale(0.3f);
          fX=0;
          fY=0;
  
      }
  
      @Override
      public void render() {
          Gdx.gl.glClearColor(1, 0, 0, 1);
          Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  
  
          batch.begin();
          sprite.draw(batch);
          batch.end();
  
  
  
      }
  
      @Override
      public void dispose() {
          batch.dispose();
          img.dispose();
      }
  }
  </code></pre>