java - How to increment time every second in Libgdx -


i try add time game increment every second. how fix that?

i add code below

float timer; timer += delta; if(timer<=delta+1000)//every 1 sec {   time = time+1;   timepoint.setsentence(""+time/100);   timer = 0f;  } 

as note, delta gdx.graphics.getdeltatime(). 'time' string. looks time increment slowly. means when time run 1,5 sec, 'time' still increase 1. divide 100 because if not increase more faster/sec,

i use timeutils class libgdx produced similar result.

thanks before.

this should work. note time/100 results in 0 0-99 , 1 100-199. that's not effect wanted.

float timer;  timer += delta; if (timer >= 1) {     time++;     timepoint.setsentence(""+time);     timer -= 1; } 

the problem set timer 0. if 1.1f example (because last delta 0.1f), lose 100ms. don't reset timer 0f, decrease 1f instead.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -