我能否使用透视相机来渲染我的精灵批次?
所有我的精灵(这些使用相同纹理加载的)看起来大小相同,但是我希望相机位于屏幕底部某个高度,这样那些靠近屏幕顶部的精灵看起来更小。现在它看起来像左边的那张图片,但是我希望它看起来像右边的那张图片:
是的,尽管您可能需要稍微调整/缩放您的坐标(您可以使用spriteBatch.setTransformMatrix在一次调用中完成)。这里是一个小例子:
public class SpriteBatch3DTest extends GdxTest {
PerspectiveCamera cam;
CameraInputController camController;
SpriteBatch spriteBatch;
Texture texture;
@Override
public void create () {
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0f, 8f, 8f);
cam.lookAt(0,0,0);
cam.near = 0.1f;
cam.far = 300f;
cam.update();
spriteBatch = new SpriteBatch();
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
}
@Override
public void render () {
camController.update();
spriteBatch.setProjectionMatrix(cam.combined);
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
spriteBatch.begin();
spriteBatch.draw(texture, -5f, -5f, 10f, 10f);
spriteBatch.end();
}
@Override
public void dispose () {
spriteBatch.dispose();
texture.dispose();
}
public boolean needsGL20 () {
return true;
}
public void resume () {
}
public void resize (int width, int height) {
}
public void pause () {
}
}