我有問題來集中我的精靈動畫有誰能給我一個燈?不能集中動畫(libGdx)
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stateTime += Gdx.graphics.getDeltaTime();
currentFrame = walkAnimation.getKeyFrame(stateTime, true);
batch.setProjectionMatrix(cam.combined);
batch.begin();
batch.draw(currentFrame, Gdx.graphics.getWidth()/2 - ((walkSheet.getWidth()/FRAME_COLS)/2), Gdx.graphics.getHeight()/2 - ((walkSheet.getHeight()/FRAME_ROWS)/2), width/2, height/4);
我的動畫正在向左畫幾個像素。
它看起來像你試圖用'walkSheet.getWidth()/ FRAME_COLS'計算當前幀的寬度...爲什麼不直接調用'currentFrame.getWidth()'而已? – DannyMo
@damo感謝您的答案,但它只是給了我相同的結果,當在桌面上運行時,動畫會稍微向右移動,在我的手機上運行時會稍微向左,可能不是那段代碼我必須改變? –
我也會確保你正確定義了你的TextureRegion。 'TextureRegion'可能會在屏幕中居中,但精靈可能不會在'TextureRegion'中居中。 – DannyMo