简体   繁体   中英

Stop moving camera(LIBGDX)

hi everybody i've been trying to sto moving my camera at the end of my map, but it continue moving this is my code:

@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();

}

}

this is the code that move the camera on the map, but the camera dosen't stop moving at the end of the map, please help me guys how can i make the camera stop moving when it reach the end of the map??????

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

Hope you understand the above mess!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM