我做了一個叫做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的頌歌嗎? –
精心製作.......... – Elltz
你在哪裏做classObj?這是一個全局變量嗎?給我們一些工作在這裏! –