endGameというブール値を作成しました。ボタンをクリックすると、に設定されます。false
次に、別のクラスで、ブール値が存在するクラスのオブジェクトを作成しました。そして、何かが起こったとき、endGameは次のように設定され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);
}
次に、別のクラスで、ブール値が存在するクラスのオブジェクトを作成しました
endGame
変数は静的ではないと思います。それ以外の場合は、ブール値が存在するクラスのオブジェクトにアクセスするために作成する必要はありません。
つまりendGame
、関連するクラスの1つのオブジェクトでtrueに設定した場合、endGame
そのクラスの別のオブジェクトの値は更新されません。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加