I am developing a game in which i want user to collect bonus after every 70 seconds..here is my code to track time but i am unable do get the solution..I am new to Libgdx pl
The Screen's render(float delta) function gives you the amount of time that has passed by since the last render(..) call, in miliseconds, as float.
Therefore, a timer would just be the following:
public class GameScreen implements Screen
{
private float bonusTimer;
public GameScreen()
{
bonusTimer = 70f;
}
@Override
public void render(float delta)
{
for(float iter = 0; iter < delta; iter += 0.125f)
{
float iterNext = iter + 0.125f;
float currentDelta;
if(iterNext > delta)
{
currentDelta = delta - iter;
}
else
{
currentDelta = iterNext - iter;
}
bonusTimer -= currentDelta;
if(bonusTimer <= 0)
{
bonus();
bonusTimer += 70f;
}
...
}
}
...
}
What you would want to do is set an instance of this GameScreen to be the active Screen in the descendant of the Game, your core class. Look here for more info: https://github.com/libgdx/libgdx/wiki/Extending-the-simple-game
Adjust the logic as needed (for example, having your own GameModel that resets itself upon the start of the game).