I'm trying to draw a texture. This works well as long as I do this in my Screen's render method:
public void render(float delta) {
batch.begin();
batch.draw(new Texture(Gdx.files.internal("badlogic.jpg")), 0f, 0f, 100, 100f);
batch.end();
}
However, if I render the Texture withing my Actor, the image is not displayed correctly. Instead of the image I only see one pixel which is far too big.
// The constructor of my Screen
public GameScreen(Main game) {
Gdx.gl.glClearColor(1, 1, 1, 1f);
Gdx.gl.glClear(Gdx.gl.GL_COLOR_BUFFER_BIT);
viewport = new ExtendViewport(100f, 100f * (4f / 3f), 100f, 100f * (2f / 1f));
viewport.apply();
viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
stage = new Stage(viewport, batch);
stage.addActor(new MyActor());
//...
}
//The Actor-Class:
public class MyActor extends Actor {
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(new Texture(Gdx.files.internal("badlogic.jpg")), 0f, 0f, 100, 100f);
}
}
Thanks in advance :)