试图在libGDX中显示一个矩形(android)

时间:2014-11-18 22:18:45

标签: java android libgdx 2d collision

    platformR = new ShapeRenderer();
    platformR.setProjectionMatrix(camera.combined);
    platformR.begin(ShapeType.Filled);
    platformR.identity();
    platformR.setColor(new Color(0, 1, 0, 1));
    platformR.rotate(0, 0, 1, 90);*/
    platformR.rect(getxPos(), getyPos(), getSprite().getWidth() + getxPos(),
            getSprite().getHeight() + getxPos());
    platformR.end();

这是我显示矩形的代码,但矩形不显示。有什么我想念的吗?

1 个答案:

答案 0 :(得分:0)

确保将.begin()/ .end()方法调用放在render()方法中。

public class ShapeRendererExample extends ApplicationAdapter {
ShapeRenderer shapeRenderer;

@Override
public void create () {
    shapeRenderer = new ShapeRenderer();
}

@Override
public void render () {
    shapeRenderer.begin(ShapeType.Filled);
    shapeRenderer.setColor(new Color(1, 0, 0, 1));
    shapeRenderer.rect(100f, 100f, 100f, 100f);
    shapeRenderer.end();
}

private void clearScreen()
{
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
}
}