rayHandler.render()导致box2DLightsVersion出现黑屏

时间:2015-07-14 23:48:06

标签: java libgdx

如果我评论rayHandler.render(),我会看到此屏幕..

screenshot

然而,当我取消注释时,屏幕变黑。有什么想法吗?

public class GameScreen implements Screen {

    private ColorCatch game;
    private OrthographicCamera camera;

    private World world;
    private RayHandler rayHandler;
    private Body body;

    private ShapeRenderer shapeRenderer = new ShapeRenderer();

    public GameScreen (final ColorCatch gam) {

        this.game = gam;

        camera = new OrthographicCamera();
        camera.setToOrtho(false, 800, 480);

        world = new World(new Vector2(0.0f, -98.0f), true);
        rayHandler = new RayHandler(world);
        new PointLight(rayHandler, 1000, new Color(1,1,1,1), 5.0f, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);

        CircleShape shape = new CircleShape();
        shape.setRadius(3.0f);
        FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        BodyDef bd = new BodyDef();
        bd.position.set(new Vector2(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2));
        bd.type = BodyType.DynamicBody;

        body = world.createBody(bd);
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        camera.update();
        shapeRenderer.setProjectionMatrix(camera.combined);

        world.step(Gdx.graphics.getDeltaTime(), 8, 1);

        Vector2 pos = body.getPosition();

        shapeRenderer.begin(ShapeType.Filled);
        shapeRenderer.setColor(Color.RED);
        shapeRenderer.identity();
        shapeRenderer.translate(pos.x, pos.y, 0);
        shapeRenderer.circle(0.0f, 0.0f, 66.0f);
        shapeRenderer.end();

        shapeRenderer.begin(ShapeType.Filled);
        shapeRenderer.setColor(0, 1, 0, 1);
        shapeRenderer.identity();
        shapeRenderer.rect(5, 5, 10, 10);
        shapeRenderer.circle(25, 25, 10);
        shapeRenderer.end();

        rayHandler.setCombinedMatrix(camera);
        rayHandler.update();
        //rayHandler.render(); //FIXME this line causes blank screen
    }

    @Override
    public void dispose() {
        game.getBatch().dispose();
        bg.dispose();
    }

    @Override
    public void show() {
                // TODO Auto-generated method stub
    }

    @Override
    public void resize(int width, int height) {
        // TODO Auto-generated method stub
    }

    @Override
    public void pause() {
        // TODO Auto-generated method stub
    }

    @Override
    public void resume() {
        // TODO Auto-generated method stub
    }

    @Override
    public void hide() {
        // TODO Auto-generated method stub
    }
}

0 个答案:

没有答案