I am trying to add a timer for power ups in my game. What I am trying to do is change a parameter (like jump height for example) after the player has collided with the power up box but it should only apply for 4 seconds. I have already written the collision coding and have added a random element to choose which power up is activated. I have also added a power up that will not use the timer (adding 1 to the score).
Searching google I found code using various methods like Gdx.graphics.getDeltaTime() and Timer.schedule but I can't seem to get them to work, maybe I am coding them incorrectly. I've been trying to use code like this but when using System.out.println(timeSinceCollision), I keep getting a constant value every time and it doesn't seem to be increasing.
float timeSinceCollision = 0;
timeSinceCollision += delta;
if(timeSinceCollision < 4f) {
// the action
} else {
// reset
}