をscene2d:正確な位置は、私は私のlibGDXアプリ、以下のようなものではオフに設定プレス可能なピアノのキーをレイアウトしたい
キーが押されたとき、私はからそれを変更する必要があります(画像ボタンを使用すると簡単です)。
私が苦労しているのは、すべてのボタンをピアノキーボードに似たものにレイアウトする方法です。白いピアノのキー画像は長方形ですが、黒いピアノキーをその上に置く必要があります。以下は、私の白いピアノのキーイメージがどのように見えるかを示しています。黒い音符を入れるデッドスペースが上隅にあります。
テーブルはギャップで私を残してサイド・バイ・サイドのすべてを、レイアウトとしてTable
を使用すると、動作しません。私はあなたがStack
を使用することができますが、それはちょうど最後の上に直接すべての子供を置くので、どちらも役に立たないようです。
Skin skin;
Stage stage;
SpriteBatch batch;
private TextButton button1;
private TextButton button2;
@Override
public void create() {
batch = new SpriteBatch();
stage = new Stage();
Gdx.input.setInputProcessor(stage);
createSkin();
Table table = new Table();
table.setFillParent(true);
stage.addActor(table);
// Create a button with the "default" TextButtonStyle. A 3rd parameter can be used to specify a name other than "default".
button1 = new TextButton("First note", skin);
button1.getLabel().setFontScale(5);
button2 = new TextButton("Second note", skin);
button2.getLabel().setFontScale(5);
table.add(button1).width(500).height(500);
table.add(button2).width(500).height(200);
}
@Override
public void render() {
super.render();
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}
@Override
public void resize (int width, int height) {
stage.getViewport().update(width, height, true);
}
@Override
public void dispose() {
stage.dispose();
skin.dispose();
}
private void createSkin() {
skin = new Skin();
Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.fill();
skin.add("white", new Texture(pixmap));
skin.add("default", new BitmapFont());
TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.down = skin.newDrawable("white", Color.BLUE);
textButtonStyle.checked = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.over = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.font = skin.getFont("default");
skin.add("default", textButtonStyle);
}
このレンダリング:それは助け場合
は、私のコードは次のようなものである 私はテーブルを使用して言うことができる限りの事を重ね合わせる方法はありません
が、私はすることができますそれを行う別の方法を見つけることはありません。これはscene2dを使って可能ですか?