I have clouds that are scrolling left to right. I’m using an OrthographicCamera to do so. I was wondering, how would i adjust these clouds in order to cause them to move towards the screen, rather than from left to right? Could i still use the Orthographic camera to do so? How would i do this?
My code is as follows:
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();
}
Orthographic projections by definition store no depth information. The only way you can make the appearance of clouds coming towards the screen is to increase the sprite size – but I advise against it.
You should use a non-orthographic projection and just use the z-axis.