0

I will show scoring . isCollides is a function that checks a collision.

if(isCollides(prize, splash))

in other function Working well but in runnable function not working.

  private Runnable Scoring =new Runnable() {

   @Override
   public void run() {
        // TODO Auto-generated method stub
        try {

        if(isCollides(prize, splash))
        {
            score++;
            p.setText(":"+score);

        }               

    }
    catch (Exception e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

     mHandler.postDelayed(mStartVamp, 3000);

}
      };


              public boolean isCollides(Sprite Sprite1 ,Sprite Sprite2) throws Exception
                {
            float diffX = Math.abs( (Sprite1.getX() +  Sprite1.getWidth()/2 )- 
                         (Sprite2.getX() + Sprite2.getWidth()/2 ));
            float diffY = Math.abs( (Sprite1.getY() +  Sprite1.getHeight()/2 )- 
                         (Sprite2.getY() + Sprite2.getHeight()/2 ));

            if(diffX < (Sprite1.getWidth()/2 + Sprite2.getWidth()/3) 
                       && diffY < (Sprite1.getHeight()/2 + Sprite2.getHeight()/3))
            {

               return true;
            }
            else{
              return false;
            }

        }
Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
zeinab21
  • 1
  • 1

1 Answers1

0

Any change you make to AndEngine entities needs to happen on the AndEngine UpdateThread - so your call to p.setText() should be enveloped in a runOnUpdateThread() call - see this thread for how to - How can repair this error? "java.lang.IndexOutOfBoundsException"

Community
  • 1
  • 1
jmroyalty
  • 2,527
  • 1
  • 17
  • 21