How to add a slow motion effect to my player?

时间:2016-08-31 18:37:34

标签: android animation libgdx game-physics motion

I want to move my player in slow motion to the right and to the left. I can move my player, but it isn't look cool. I want to see slow motion when the player moves. How can I do this?

My Player is going through to y axis. I have 2 buttons to left and to right for movement.

I can move the player to the direct position, but I want to use slow motion.

PlayScreen: this is my PlayScreen screenshot

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;
        }
    });

my render method

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();


}

1 个答案:

答案 0 :(得分: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

画出你的精灵