我的云从左向右滚动。我正在使用正交相机来执行此操作。我想知道,我将如何调整这些云以使它们向屏幕移动,而不是从左到右?我仍然可以使用正交相机来执行此操作吗?我该怎么做?
我的代码如下:
public void create() {
sky = new SkyFlux();
//getting the height and width for setup purposes
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
//setting up camera and batch
camera = new OrthographicCamera(1, h/w);
//setting up sky
for(Texture texture:sky.getTexture())
textures.add(texture);
//Adding the sky related sprites
for(Sprite sprite:sky.getSprite())
skySprites.add(sprite);
}
public void render() {
//clearing everything out
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
time += Gdx.graphics.getDeltaTime();
if(time > 1.0f)
time = 0.0f;
float speed = 1.0f;
//Adjusting the speed of the sprites except the first sprite which is the base image.
for(int i=1;i<skySprites.size();i++) {
skySprites.get(i).setV(time+speed);
skySprites.get(i).setV2(time);
speed = speed+1.0f;
}
//setting up
batch.setProjectionMatrix(camera.combined);
//begging draw
batch.begin();
//items to be drawn
//TODO: add other items to be drawn here
for(Sprite sprite:skySprites)
sprite.draw(batch);
//ending draw
batch.end();
}
最佳答案
根据定义,正交投影不存储深度信息。使云出现朝向屏幕的唯一方法是增加 Sprite 大小 - 但我建议不要这样做。
您应该使用非正交投影并仅使用 z 轴。
关于java - 侧滚云,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11068789/