I would like to let the sprite where I left it in the screen, and drag the camera in the world. But the sprite sticks to the camera, and is still at the bottom of the screen when I drag the camera.
This is not happening with a tilemap (the .tmx file), and a renderer : the camera can drag over the tilemap, and the tilemap does not stick to the camera. With a spriteBatch tough, the sprite stays at the bottom of the screen.
Here is my code:
map = MyLoader.manager.get("data/mMap.tmx");
float unitScale = 1 / 64f;
renderer = new OrthogonalTiledMapRenderer(map, unitScale);
@Override
public void render() {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
camera.update();
renderer.setView(camera);
renderer.render();//tilemap works fine
//sprite
//batchMap.setProjectionMatrix(camera.combined);//wrong
batchMap.begin();
if ( scrFactoryMap.maps.size() > 0 ) {
scrFactoryMap.getMap(0).draw(batchMap);//sprite sticks to the camera
}
str = "string";
font.draw(batchMap, str, 50,50);//font sticks to the camera
batchMap.end();
}
private void slerpCamera(){
//...
camera.position.add( camX, camY, 0 );
camera.update();
}
Why did you comment this, an put wrong on it?
//sprite
//batchMap.setProjectionMatrix(camera.combined);//wrong
You must set the new ProjectionMatrix to the SpriteBatch whenever you transform (i.e. move) your camera.
Uncomment it :)