Well, i'm facing a strange problem with my code. I'm trying to remove a sprite named ice when either of player, enemy or the ground comes in contact with the ice. The contact is made successfully and the ice is hidden after the contact but due to some reasons the player,enemy and the ground still comes in contact with the ice. I want the ice object to be completely removed from the scene when contact is made. I'm using the below code:
public void beginContact(Contact contact) { // TODO Auto-generated method stub Fixture x1 = contact.getFixtureA(); Fixture x2 = contact.getFixtureB();
if (x1.getBody().getUserData().equals("player")
&& x2.getBody().getUserData().equals("ice") && gb.isVisible()==true) {
Log.i("Contact Made", "CN");
detachChild(gb);
gb.setVisible(false);
score = score + 1;
scoreText.setText("Score: " + score);
}
if (x1.getBody().getUserData().equals("ground")
&& x2.getBody().getUserData().equals("ice") && gb.isVisible()==true) {
detachChild(gb);
gb.setVisible(false);
}
if (x1.getBody().getUserData().equals("enemy")
&& x2.getBody().getUserData().equals("ice") && gb.isVisible()==true) {
detachChild(gb);
gb.setVisible(false);
}
}