我可以使用透视相机渲染我的精灵批次吗?
我的精灵(装有相同纹理的精灵)看起来大小相同,但我希望相机在某个高度处放置在屏幕底部,因此位于屏幕顶部附近的精灵看起来更小.现在它看起来像左边的那个,但我希望它看起来像右边的那个:
是的,虽然您可能需要稍微调整/缩放坐标(您可以使用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 () {
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2535 次 |
| 最近记录: |