점수와 시간 및 이미지를로드하는 것처럼 보이지만 점수가 높을 때 이미지를 업데이트하고 변경하려고하는 HUD를 그리려는 것입니다. 작동 안함. 아마 나는 update 메소드에서 새로운 테이블을 정의하고 매번 다른 이미지를 넣을 수 있다고 생각했지만 매번 새로운 테이블을 정의하고 싶지는 않습니다. 단지 표 안에 이미지를 업데이트 할 수 어쨌든이 : 이 코드입니다 :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
하지만 여기에 새 테이블을 만들지 않고 개체를 테이블에 추가 할 수 있습니다. 테이블을 만들고 메서드에서 개체를 할당하고 업데이트 메서드에서 호출하면 많은 테이블이 생성됩니다. –