LibGdx OrthographicCamera 翻译
LibGdx OrthographicCamera translation
我正在尝试移动相机以滚动到我的游戏中,但没有任何反应。
我的代码:
public class Terrain implements Screen {
@Override
public void show() {
widht = Gdx.graphics.getWidth();
height = Gdx.graphics.getHeight();
cam = new OrthographicCamera();
cam.setToOrtho(true, widht, height);
batch = new SpriteBatch();
batch.setProjectionMatrix(cam.combined);
render = new ShapeRenderer();
render.setProjectionMatrix(cam.combined);
render.setAutoShapeType(true);
cam.update();}
@Override
public void render(float delta) {
processInput();
Gdx.gl.glClearColor(0.929f, 0.819f, 0.772f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(cam.combined);
batch.begin();
render.begin();
render.rect(0,50,1000,25);
render.end();
batch.end();
}
private void processInput() {
if(Gdx.input.isTouched()){
cam.translate(25,0);
cam.update();
}
}
当我点击屏幕时没有任何反应。如果我查看相机的位置,她移动得很好,但矩形仍然在同一个地方。
知道我的错误吗?
这是因为ShapeRenderer
默认为相机坐标。
如果您想更改此设置,您需要将渲染器上的投影矩阵设置为其他内容。
例如:
@Override
public void render(float delta) {
processInput();
Gdx.gl.glClearColor(0.929f, 0.819f, 0.772f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(cam.combined);
batch.begin();
// Switch to the batch instead of the default.
render.setProjectionMatrix(batch.getProjectionMatrix());
render.begin();
// Changed the size of the rectangle so it's easier to see.
render.rect(100, 50, 100, 25);
render.end();
batch.end();
}
现在,当您点击屏幕时,矩形会向左移动,直到它不再可见。
我正在尝试移动相机以滚动到我的游戏中,但没有任何反应。
我的代码:
public class Terrain implements Screen {
@Override
public void show() {
widht = Gdx.graphics.getWidth();
height = Gdx.graphics.getHeight();
cam = new OrthographicCamera();
cam.setToOrtho(true, widht, height);
batch = new SpriteBatch();
batch.setProjectionMatrix(cam.combined);
render = new ShapeRenderer();
render.setProjectionMatrix(cam.combined);
render.setAutoShapeType(true);
cam.update();}
@Override
public void render(float delta) {
processInput();
Gdx.gl.glClearColor(0.929f, 0.819f, 0.772f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(cam.combined);
batch.begin();
render.begin();
render.rect(0,50,1000,25);
render.end();
batch.end();
}
private void processInput() {
if(Gdx.input.isTouched()){
cam.translate(25,0);
cam.update();
}
}
当我点击屏幕时没有任何反应。如果我查看相机的位置,她移动得很好,但矩形仍然在同一个地方。
知道我的错误吗?
这是因为ShapeRenderer
默认为相机坐标。
如果您想更改此设置,您需要将渲染器上的投影矩阵设置为其他内容。
例如:
@Override
public void render(float delta) {
processInput();
Gdx.gl.glClearColor(0.929f, 0.819f, 0.772f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(cam.combined);
batch.begin();
// Switch to the batch instead of the default.
render.setProjectionMatrix(batch.getProjectionMatrix());
render.begin();
// Changed the size of the rectangle so it's easier to see.
render.rect(100, 50, 100, 25);
render.end();
batch.end();
}
现在,当您点击屏幕时,矩形会向左移动,直到它不再可见。