停止移动相机(LIBGDX)

时间:2014-09-04 13:32:35

标签: java android camera libgdx

大家好,我一直试图在地图的末尾移动我的相机,但它继续移动这是我的代码:

@Override
public void render(float delta) {       
    //moving tiled map
    camera.position.x=camera.position.x+Gdx.graphics.getDeltaTime()*200;

    camera.update();
    //...........................................

    Gdx.gl.glClearColor(1, 0, 0, 0);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);


    // renderer camera and map
    renderer.setView(camera);
    renderer.render();
    //...................................................

}

@Override
public void show() {

    batch = new SpriteBatch();


    map = new TmxMapLoader().load("maps/map1.tmx");

    renderer = new OrthogonalTiledMapRenderer(map);

    camera = new OrthographicCamera();
}

@Override
public void hide() {


}

@Override
public void create() {

}

@Override
public void resize(int width, int height) {
    camera.viewportWidth = width;
    camera.viewportHeight = height;
    camera.position.set(width/2f, height/3f, 0); //by default camera position on (0,0,0)
    camera.update();


}

@Override
public void render() {



}

@Override
public void pause() {


}

@Override
public void resume() {


}

@Override
public void dispose() {
    map.dispose();
    renderer.dispose();

}

}

这是在地图上移动相机的代码,但是相机在地图末端停止移动,请帮助我们如何让相机在到达结束时停止移动地图??????

1 个答案:

答案 0 :(得分:0)

        if (camera.position.x + camera.viewportWidth / 2 >= Float
            .parseFloat(currentMap.getProperties().get("width").toString())
            * TILE_SIZE) {
            camera.position.x = Float.parseFloat(currentMap.getProperties()
            .get("width").toString())
                    * TILE_SIZE - camera.viewportWidth / 2;
        }

希望你能理解上面的混乱!