侧滚动云

时间:2012-06-17 03:50:17

标签: java android android-emulator libgdx

我有从左到右滚动的云。我正在使用OrthographicCamera这样做。我想知道,我如何调整这些云以使它们向屏幕移动,而不是从左到右?我还能使用正交相机吗?我该怎么做?

我的代码如下:

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();
}

1 个答案:

答案 0 :(得分:2)

根据定义,正交投影不存储深度信息。你可以让云的外观朝向屏幕的唯一方法是增加精灵的大小 - 但我建议反对它。

您应该使用非正交投影,只使用z轴。