Libgdx:在Actor中绘制的纹理太大了

时间:2018-04-15 20:43:23

标签: libgdx actor stage scene2d spritebatch

我试图绘制纹理。只要我在屏幕的渲染方法中执行此操作,这种方法就可以正常工作:

public void render(float delta) {
    batch.begin();
    batch.draw(new Texture(Gdx.files.internal("badlogic.jpg")), 0f, 0f, 100, 100f);
    batch.end();
}

Image: working

但是,如果我使用我的Actor渲染纹理,则图像无法正确显示。而不是图像,我只看到一个太大的像素。

// 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);
}
}

Image: not working

提前致谢:)

1 个答案:

答案 0 :(得分:0)

问题是由于我使用了SpriteBatch来绘制纹理和ShapeRenderer。 解决方案:

batch.end(); //!!
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
shapeRenderer.line(...);
//...
shapeRenderer.end();
batch.begin();