如何为我的播放器添加慢动作效果?

问题描述 投票:0回答:1

我想将我的播放器以慢动作向右和向左移动。我可以移动我的播放器,但它看起来并不酷。我想在玩家移动时看到慢动作。我怎样才能做到这一点?

我的玩家正在经历y轴。我有2个左右按钮用于移动。

我可以将玩家移动到直接位置,但我想使用慢动作。

播放屏幕:

public float speed = 0.09f;

 buttonimage.addListener(new ClickListener() {
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
        {

            player.position.x -= 300 * speed;



            return true;
        }
    });

我的渲染方法

public void render(float delta) {


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



    player.position.y += 500 * Gdx.graphics.getDeltaTime();
    sb.setProjectionMatrix(camera.combined);
    sb.begin();
    sb.draw(bg, 0, camera.position.y - (camera.viewportHeight/2));
    sb.draw(player.texture, player.getPosition().x , player.getPosition().y);
    for (Tube tube : tubes) {
        sb.draw(tube.getlefttube(), tube.getposlefttube().x, tube.getposlefttube().y);
        sb.draw(tube.getrighttube(), tube.getposrighttube().x, tube.getposrighttube().y);
        sb.draw(tube.getLight() , tube.getPoslight().x , tube.getPoslight().y);
    }





    delta*=speed;
    sb.end();
    update(delta);

    stage.draw();


    app.batch.begin();
    app.font23.draw(app.batch,"Lights collected :" + dropsGathered , 0, 720);
    app.batch.end();


}
android animation libgdx game-physics motion
1个回答
0
投票

我可以告诉你如何使用Box2D做到这一点

此页面的示例:

// apply right impulse, but only if max velocity is not reached yet
if (Gdx.input.isKeyPressed(Keys.D) && vel.x < MAX_VELOCITY) {
     this.player.body.applyLinearImpulse(0.80f, 0, pos.x, pos.y, true);
}

然后你可以相对于player.body绘制你的精灵

© www.soinside.com 2019 - 2024. All rights reserved.