スコア、時間、画像の読み込みを表示するHUDを描画しようとしていますが、スコアが高くなると画像を更新して変更したいのですが、働いていない。私は、更新メソッドで新しいテーブルを定義し、毎回異なるイメージを置くことができると思うかもしれませんが、毎回新しいテーブルを定義したくありません。唯一のテーブル内の画像を更新するために、とにかくそこにある: これはコードです:Libgdxは動的にテーブル内の画像を変更します
public class Hud implements Disposable{
public Stage stage;
private Viewport viewport;
private static Integer worldTimer;
private float timecount;
private static Integer score;
Label countdownLabel;
private static Label scorelabel;
private Label timelabel;
private Label levellabel;
private Label worldlabel;
private Label mariolabel;
private Image loading;
private Table table;
public Hud(SpriteBatch sb)
{
worldTimer=40;
timecount=0;
score=0;
viewport=new FitViewport(Fruits.V_WIDTH,Fruits.V_HIEGT,new OrthographicCamera());//2
stage=new Stage(viewport,sb);//stage is as box and try to put widget and organize things inside that table
table = new Table();
table.top();//table at top of our stage
table.setFillParent(true);//table is now fill all the stage
countdownLabel=new Label(String.format("%02d",worldTimer),new Label.LabelStyle(new BitmapFont(), Color.BLACK));//label for gdx
scorelabel=new Label(String.format("%02d",score),new Label.LabelStyle(new BitmapFont(), Color.BLACK));//label for gdx
timelabel=new Label("TIME",new Label.LabelStyle(new BitmapFont(), Color.BLACK));//label for gdx
levellabel=new Label("1-1",new Label.LabelStyle(new BitmapFont(), Color.BLACK));//label for gdx
worldlabel=new Label("WORLD",new Label.LabelStyle(new BitmapFont(), Color.BLACK));//label for gdx
mariolabel=new Label("Score" ,new Label.LabelStyle(new BitmapFont(), Color.BLACK));//label for gdx
loading = new Image(new Texture("10%.png"));
//loading.setSize(40, 10);
table.add(mariolabel).expandX().padTop(10);
table.add(timelabel).expandX().padTop(10);
table.add(worldlabel).expandX().padTop(10);
table.row();
table.add(scorelabel).expandX();
table.add(countdownLabel).expandX();
table.add(loading).width(50).height(10);
stage.addActor(table);
}
public void update(float dt)
{
timecount+=dt;
if (timecount>1)
{
worldTimer--;
if(worldTimer>=0) {
countdownLabel.setText(String.format("%02d", worldTimer));
loading=new Image(new Texture("90.png"));
}
timecount=0;
}
}
public static int getTime()
{
return worldTimer;
}
public static void addScore(int value)
{
score +=value;
scorelabel.setText(String.format("%02d",score));
}
public static int getScore()
{
return score;
}
@Override
public void dispose() {
stage.dispose();
}
}
この質問を[game development](http://gamedev.stackexchange.com/)サイトに移動することを検討してください。 –
オブジェクトと参照の違いを理解するには、Javaの基本について少しお読みください。参照を再割り当てすると、以前に参照されたオブジェクトに何も起きることはありませんが、おそらくガベージコレクションのために利用できるようになります。 – Tenfour04
ここで新しいテーブルを作成せずにテーブルにオブジェクトを追加する方法 テーブルを作成してメソッド内でオブジェクトを割り当て、更新メソッドで呼び出すと、多くのテーブルが作成される –