私はこの問題に遭遇しました。私は単純に分類することができません。 私はLibGdxの助けを借りてゲームを作っており、チャットバブルの機能を作りようとしています。問題は、ラベルスタイルのバックグラウンドを9patchドロワブルに変更しようとすると、それがうまくスケールされないということです。9patchのLibGdxラベルの背景
それがどのように見えるかpublic class ChatBubble
{
private Label textLabel;
private BitmapFont font;
private Label.LabelStyle lStyle;
private int scaledWidth = 0;
private int scaledHeight = 0;
private Timer.Task currentTask;
private Texture bkg;
public ChatBubble()
{
font = new BitmapFont();
font.setColor(Color.BLACK);
bkg = new Texture("data/ui/chatb.9.png");
NinePatch np = new NinePatch(bkg,11,11,9,10);
NinePatchDrawable npd = new NinePatchDrawable(np);
lStyle = new Label.LabelStyle(font,font.getColor());
lStyle.background = npd;
textLabel = new Label("",lStyle);
textLabel.setVisible(false);
textLabel.setAlignment(Align.center);
currentTask = new Timer.Task() {
@Override
public void run() {
textLabel.setVisible(false);
}};
}
public void show(String text, float duration)
{
if(currentTask.isScheduled())currentTask.cancel();
textLabel.setText(text);
textLabel.setVisible(true);
scaledHeight = (int)textLabel.getPrefHeight();
scaledWidth = (int)textLabel.getWidth()/2;
Timer.schedule(currentTask,duration);
}
public void show(String text)
{
if(currentTask.isScheduled())currentTask.cancel();
textLabel.setText(text);
textLabel.setVisible(true);
scaledHeight = (int)textLabel.getPrefHeight();
scaledWidth = (int)textLabel.getWidth()/2;
Timer.schedule(currentTask,(float)(text.length()*0.1));
}
public void draw(SpriteBatch batch, float x, float y)
{
if(!textLabel.isVisible())return;
textLabel.setPosition(x - scaledWidth, y + scaledHeight);
batch.begin();
textLabel.draw(batch, 1);
batch.end();
}
}
ゲーム内:
9batchがどのように見えるか:
任意の助けいただければ幸いです!
更新: 私の9patchは大丈夫ですが、問題はsetText()が呼び出されたときにラベルのサイズが更新されていないことがわかりました。コンストラクタから幅と高さが0です。ラベルの()もこれを解決しません。
私は前にそれを試しましたが、残念なことに何も変更されません。 これは私が今解決した方法はラベル=新しいラベル( ""、stylewithbkg)です。 私は新しいチャットバブルを表示するたびに..これは非常にスマートメモリ賢明なthoではない:( –