Libgdx纹理在移动时会闪烁

时间:2014-10-19 21:07:33

标签: java android libgdx render flicker

我有一张图片,我想向右移动。为此,每次调用渲染时,我都会将x位置增加200f*Gdx.graphics.getDeltaTime();。我已经阅读了其他人员遇到类似问题的帖子,但他们没有乘以deltaGdx.graphics.getDeltaTime()。因为我显然这样做,为什么我的图像在移动时会闪烁/振动?

我的代码:

public class gm extends Game{
    OrthographicCamera cam;
    SpriteBatch batch;
    Texture img;
    float x = 0;     

    @Override
    public void create () {
        batch = new SpriteBatch();
        img = new Texture("badlogic.jpg");  
        cam = new OrthographicCamera();
        cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    }

    @Override
    public void render () {
        super.render();
        //x += 200f*Gdx.graphics.getDeltaTime(); 
        Gdx.gl.glClearColor(1, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        cam.update();
        batch.setProjectionMatrix(cam.combined);
        batch.begin();
        batch.draw(img, x += 100f*Gdx.graphics.getDeltaTime(), 0);      
        batch.end();
    }
}

0 个答案:

没有答案