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;
}
}