Search code examples
javaandroidlibgdx

libGDX: game universal speed


I am new to libGDX, i'm trying to make a feature in my game where the player clicks on a button and the whole game speed is increased by a factor of 2. i dont want to change every game element's speed, i'm looking for a global option of controlling the 'game tick' speed.


Solution

  • Well to conserve a proper frame independant application (game) you must use the time passed between two frames. Libgdx already gives you this in the render method of your screens if you use Game in the form a a float argument called delta or deltaTime. If you don't, you can still use Gdx.graphics.getDeltaTime() to get it.

    If you already do this (you should!). Just multiply it for 2 before the game updates.

    @Override
    public void render(float delta){
        delta = delta * 2;
        //game logic
        ...
    }