I made a boolean called endGame, and when I click a button it will be set to false
, and then on another class I made an object for the class where my boolean is. And when something happen the endGame will be set to true
:
if(condition==true){ //the endGame variable will be equal to true only on this class
classObj.endGame=true;
}
//on the other class where the endGame is Located it is still false.
//button class
public boolean endGame;
public void create(){
endGame=false;
playButton.addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
endGame=false;
System.out.println(endGame);
return super.touchDown(event, x, y, pointer, button);
}
});
}
//second class
if(sprite.getY()>=700){
buttonObj.endGame=true;
enemyIterator.remove();
enemies.remove(sprite);
}
and then on another class I made an object for the class where my boolean is
I assume the endGame
variable is not static. Otherwise you wouldn't need to create an object of the class where the boolean is in order to access it.
This means that if you set endGame
to true in one object of the relevant class, it wouldn't update the value of endGame
in different objects of that class.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments