2017-06-09 74 views
0

我有一個有效的動畫,名爲diceAnimation,其有效的TextureAtlas被稱爲dice,其中有幾幀。我遇到的問題是渲染它。我使用下面的代碼來渲染動畫,但它只顯示第一幀。如果我將timeElapsed設置爲每次添加一個而不是使用增量時間,則它會動畫,但會非常快速,忽略構造中定義的每秒幀數。任何人有想法?動畫未播放(LibGDX)

int elapsedTime; 

@Override 
public void create() { 
    batch = new SpriteBatch(); 
    dice = new TextureAtlas("textures/dice/dice.atlas"); 
    diceAnimation = new Animation<TextureRegion>(0.033f, dice.findRegions("one"), PlayMode.LOOP); 
} 

// ... 

@Override 
public void render() { 
    elapsedTime += Gdx.graphics.getDeltaTime(); 

    Gdx.gl.glClearColor(1, 0, 0, 1); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 

    batch.begin(); 
    batch.draw(diceAnimation.getKeyFrame(elapsedTime, true), 100, 100); 
    batch.end(); 
} 

回答

1

int的數據類型elapsedTime應該是float而不是int。


OFF_TOPIC

PlayMode.LOOP是diceAnimation的PlayMode所以你可以使用

batch.draw(diceAnimation.getKeyFrame(elapsedTime), 100, 100);