[英]Sprite sticks to the camera in libgdx?
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. tilemap(.tmx文件)和渲染器不会发生这种情况:相机可以拖动tilemap,而tilemap不会粘在相机上。 With a spriteBatch tough, the sprite stays at the bottom of the screen.
spriteBatch很难,精灵停留在屏幕的底部。
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 (ie move) your camera. 无论何时转换(即移动)相机,都必须将新的ProjectionMatrix设置为SpriteBatch。
Uncomment it :) 取消注释:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.