我做了一个叫做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?这是一个全局变量吗?给我们一些工作在这里! –