[英]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! 希望你理解上面的烂摊子!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.