Я создал логическое имя endGame, и когда я нажимаю кнопку, он будет установлен в false
, а затем в другом классе я создал объект для класса, где находится мое логическое значение. А когда что-то случится эндшпиль будет установлен 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);
}
Вы уверены, что это тот же экземпляр classobj? Вы уверены, что проходите через оду, которая устанавливает переменную в true? –
detailate .......... – Elltz
Где вы делали classObj? это глобальная переменная? Дайте нам что-то для работы здесь! –