Ich versuche, ein Objekt zu machen, das die Actor-Klasse erweitert. aber wenn ich die draw() -Methode der Stage aufgerufen habe, wird nur die Schaltfläche gezeichnet, die ich hinzugefügt habe. Hier ist mein Code, vielleicht kann mir hier jemand helfen?Wie kann man Schauspieler erweitern und auf der Bühne zeichnen? Libgdx
-Code für meine Screen-Klasse (Angenommen, ich alle notwendigen Methoden außer Kraft gesetzt hatte, und dass ich alle notwendigen Klassen importiert): public class Gabebildschirm Bildschirm implementiert {
SpriteBatch batch;
Game game;
Table table;
Skin skin;
Stage stage;
BitmapFont font;
TextButton button;
TextDisplay display;
public PlayScreen(MyGdxGame game, SpriteBatch batch){
this.game = game;
this.batch = batch;
//instantiating Stage, Table, BitmapFont, and Skin objects.
font = new BitmapFont(Gdx.files.internal("MyTruefont.fnt"));
table = new Table();
stage = new Stage();
skin = new Skin(Gdx.files.internal("Test.json"));
button = new TextButton("Start!", skin, "default");
display = new TextDisplay(font, this);
//Setting table properties
table.setWidth(stage.getWidth());
table.align(Align.center|Align.top);
table.setPosition(0, Gdx.graphics.getHeight());
table.padTop(30);
//Adding actors to table
table.add(button).padBottom(50);
table.add(display);
//Adding table to stage and setting stage as the input processor
stage.addActor(table);
Gdx.input.setInputProcessor(stage);
}
@Override
public void show() {
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
stage.draw();
batch.end();
}
Und hier ist meine Textdisplay-Klasse, die Schauspieler erstreckt (unter der Annahme wieder alle anderen Methoden außer Kraft gesetzt wurden, und alle notwendigen Klassen importiert wurden):
public class TextDisplay extends Actor implements Drawable {
Texture texture;
BitmapFont font;
String str;
public TextDisplay(BitmapFont font, Screen screen){
this.font = font;
texture = new Texture(Gdx.files.internal("TextArea.png"));
str = "";
setLeftWidth(texture.getWidth());
setRightWidth(texture.getWidth());
setBottomHeight(texture.getHeight());
setTopHeight(texture.getHeight());
}
@Override
public void draw(Batch batch, float x, float y, float width, float height) {
batch.draw(texture, x, y);
}
oh ok danke. Ich habe drawable implementiert, um zu sehen, ob es das Problem beheben würde. Ich schätze, ich kann das loswerden. wäre ich noch in der lage, das bild zu zeichnen, das meinen schauspieler repräsentieren soll? oder fehlt etwas? –
Auch die Label-Klasse macht nicht was ich will. –
Sie können mit der Methode 'draw' alles zeichnen, was Sie wollen. – Tenfour04