Görünmez aktörler dokunma olayları almazlar, sekmeli içerik arayüzlerinin görünürlüğünü uygun şekilde ayarlayarak sekmeli arabirimi gerçekleştirmenin en kolay yolunu yaparlar. İşte
Ben libgdx bir sekmeli arabirimi uygulamak gibi olacaktır:
package com.badlogic.gdx.tests.lwjgl;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
class Game3 extends ApplicationAdapter {
Skin skin;
Stage stage;
@Override
public void create() {
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
stage = new Stage(new ScreenViewport());
Table main = new Table();
main.setFillParent(true);
// Create the tab buttons
HorizontalGroup group = new HorizontalGroup();
final Button tab1 = new TextButton("Tab1", skin, "toggle");
final Button tab2 = new TextButton("Tab2", skin, "toggle");
final Button tab3 = new TextButton("Tab3", skin, "toggle");
group.addActor(tab1);
group.addActor(tab2);
group.addActor(tab3);
main.add(group);
main.row();
// Create the tab content. Just using images here for simplicity.
Stack content = new Stack();
final Image content1 = new Image(skin.newDrawable("white", 1,0,0,1));
final Image content2 = new Image(skin.newDrawable("white", 0,1,0,1));
final Image content3 = new Image(skin.newDrawable("white", 0,0,1,1));
content.addActor(content1);
content.addActor(content2);
content.addActor(content3);
main.add(content).expand().fill();
// Listen to changes in the tab button checked states
// Set visibility of the tab content to match the checked state
ChangeListener tab_listener = new ChangeListener(){
@Override
public void changed (ChangeEvent event, Actor actor) {
content1.setVisible(tab1.isChecked());
content2.setVisible(tab2.isChecked());
content3.setVisible(tab3.isChecked());
}
};
tab1.addListener(tab_listener);
tab2.addListener(tab_listener);
tab3.addListener(tab_listener);
// Let only one tab button be checked at a time
ButtonGroup tabs = new ButtonGroup();
tabs.setMinCheckCount(1);
tabs.setMaxCheckCount(1);
tabs.add(tab1);
tabs.add(tab2);
tabs.add(tab3);
stage.addActor(main);
Gdx.input.setInputProcessor(stage);
}
@Override
public void render() {
stage.act();
stage.draw();
}
@Override
public void dispose() {
stage.dispose();
skin.dispose();
}
public static void main (String[] args) {
new LwjglApplication(new Game3(), new LwjglApplicationConfiguration());
}
}
Farklı ekranları kullanarak düşünüyordum ama sonra yetenek ağacı uyguladıklarında ben istatistikleri güncelleme böylece oyuncu nesneyi bağlamak zorunda becerilerden ve yetenek ağacını görmek istediğinizde her zaman ekranı değiştirmem gerekiyor. İyi bir fikir olabilir, aynı zamanda birden fazla aşama ve aynı sprite toplu kullanımı hakkında, ama bir toplu argüman eklemek istiyorsanız ben de istediğim bir şey olmayan bir view-port argüman sağlamak gerekir ... Fikirler için teşekkürler . Belki de hem bir aşamayı hem de birden çok aşamayı uygulamaya çalışacağım ve hangisinin oyunum için daha uygun olduğunu göreceğim. – Andrew