2017-06-06 1 views
0

ゲームのUIで、スコアを書くためにボックスイメージにラベルを付けました。スコアで文字列を作成し、スコアが動的に変化している間に以前のスコアを消去しない-LibGdx

private void drawNoOfCoins() { 
    Label.LabelStyle style = new Label.LabelStyle(); 
    style.font = game.font2; 
    Label totalCoinLabel = new Label(coinScoreController.getTotalCoinString(), style); 

    totalCoinLabel.setPosition(showcoinImage.getWidth()/2,Constants.WORLD_HEIGHT - 2 * totalCoinLabel.getHeight()); 
    stage.addActor(totalCoinLabel); 

    totalCoinLabel.setBounds(showcoinImage.getX(), showcoinImage.getY(),showcoinImage.getWidth(), showcoinImage.getHeight()); 
    totalCoinLabel.setAlignment(Align.center);  
} 

private void ShowCoinScoreBox() { 
    showcoinImage = new Image(showScoreTexture); 
    showcoinImage.setPosition(Constants.WORLD_WIDTH/42,Constants.WORLD_HEIGHT - (showcoinImage.getHeight() * 1.5f)); 
    stage.addActor(showcoinImage); 
} 

私は、このメソッドdrawNoOfCoinsを呼び出しています()でレンダリング()とスコアが動的に更新きています。

しかし、スコアが動的に変化するたびに、更新されたスコアが前のスコアの上に表示されます。 この問題はラベルやその他のものが原因ですか? どうすれば解決できますか?

+1

インサイド

private Label totalCoinLabel; private void drawNoOfCoins() { Label.LabelStyle style = new Label.LabelStyle(); style.font = game.font2; totalCoinLabel = new Label(coinScoreController.getTotalCoinString(), style); ... } 

あなたは* *ステージにすべてのループを、スコアを追加するべきではありません!ステージのラベルをクラスの初期化中にステージに一度追加してから、スコアラベルへの参照を保持し、必要に応じて更新します。 – munyul

答えて

1

一度ApplicationListenerさんcreate()からまたは初期化のためのScreenインタフェースのshow()方法からコールShowCoinScoreBox() & drawNoOfCoins()。レンダーコールで新しいActorを作成し、ステージに追加します。

ローカルの代わりにtotalCoinLabelをグローバルに参照してください。 render()方法更新ラベルテキスト

totalCoinLabel.setText(coinScoreController.getTotalCoinString()); 
関連する問題