title: Android Libgdx and collision detection
body: <p>For my android game I use Libgdx and I detect the collision between Bob (Omino) and Plant (Pianta) with this code that works fine :
  <img src="https://i.stack.imgur.com/2LSGZ.jpg" alt="Image1">
  <strong>Assets.class</strong></p>
  
  <pre><code>pianta = new Animation(0.5f,new TextureRegion(items, 160, 384, 64, 96),
                                new TextureRegion(items, 224, 384, 64, 96));
  </code></pre>
  
  <p><strong>Pianta.class</strong></p>
  
  <pre><code>public class Pianta extends GameObject {
     public static final float PIANTA_WIDTH = 2;
     public static final float PIANTA_HEIGHT = 3;
     public static float stateTime;
     public Pianta(float x, float y) {
        super(x, y, PIANTA_WIDTH, PIANTA_HEIGHT);   
        stateTime = 0;
     }
  
      public void update(float deltaTime) {
             stateTime += deltaTime;
         }
  
  }
  </code></pre>
  
  <p><strong>World.class</strong></p>
  
  <pre><code>Pianta pianta1_0 = new Pianta(x+10,2.2f);
  piante.add(pianta1_0);
  
  private void collisionPiante(){
        int len = piante.size();
        for(int i=0;i&lt;len;i++){
           if(OverlapTester.overlapRectangles(piante.get(i).bounds,omino.bounds)){
              omino.ominoMorto();
           }
        }
     }
  </code></pre>
  
  <p><strong>WorldRender.class</strong></p>
  
  <pre><code>private void renderPiante() {
        TextureRegion keyFrame;
        int len = world.piante.size();
          for(int i = 0; i &lt; len; i++) {
              Pianta pianta = world.piante.get(i);            
              keyFrame = Assets.pianta.getKeyFrame(Pianta.stateTime, Animation.ANIMATION_LOOPING);
              batcher.draw(keyFrame,pianta.position.x, pianta.position.y, 2, 3);
          }
  
  
     }
  </code></pre>
  
  <p>but if you watch the image 2 below, you can see that Bob hit but there isn't collision with stone (Pietra) !!
  <img src="https://i.stack.imgur.com/tjntp.jpg" alt="Image2">
  This is the code :</p>
  
  <p><strong>Assets.class</strong></p>
  
  <pre><code>pietra1 = new TextureRegion(items,288,416,128,64);
  </code></pre>
  
  <p><strong>Pietra.class</strong></p>
  
  <pre><code>public class Pietra extends GameObject {
     public static float PIETRA_WIDTH = 4;
     public static float PIETRA_HEIGHT = 2;
     public Pietra(float x, float y) {
        super(x, y, PIETRA_WIDTH, PIETRA_HEIGHT);
     }
  
  }
  </code></pre>
  
  <p><strong>World.class</strong></p>
  
  <pre><code>Pietra pietra1_0 = new Pietra(x+25,2.2f);
  pietre.add(pietra1_0);
  private void collisionPietre(){
        int len2 = pietre.size();
        for(int l=0;l&lt;len2;l++){
           if(OverlapTester.overlapRectangles(pietre.get(l).bounds,omino.bounds)){
              omino.ominoMorto();
           }
        }   
     }
  </code></pre>
  
  <p><strong>WorldRender.class</strong></p>
  
  <pre><code>private void renderPietre() {
        int len = world.pietre.size();
          for(int i = 0; i &lt; len; i++) {
              Pietra pietra = world.pietre.get(i);            
             batcher.draw(Assets.pietra1,pietra.position.x, pietra.position.y, 4, 2);
          }
     }
  </code></pre>
  
  <p><strong>OverlapTester</strong></p>
  
  <pre><code>public class OverlapTester {
      public static boolean overlapRectangles (Rectangle r1, Rectangle r2) {
          if (r1.x &lt; r2.x + r2.width &amp;&amp; r1.x + r1.width &gt; r2.x &amp;&amp; r1.y &lt; r2.y + r2.height &amp;&amp; r1.y + r1.height &gt; r2.y)
              return true;
          else
              return false;
      }
  </code></pre>
  
  <p>Someone can tell me why the collision with the plant works fine and with stone Bob hit even if there is no collision? as you can see the code is the same, the only difference is that the plant is an animated object while the stone isn't.</p>