我有问题来集中我的精灵动画有谁能给我一个灯?不能集中动画(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