我怎么能每秒都做某事?[LibGDX]

2022-01-12 00:00:00 android java libgdx

假设我想制作一个循环或打印出来的东西,例如每秒打印一次Mario".我怎样才能做到这一点?似乎在任何地方都找不到任何好的教程来教这个=P

Lets say I want to make a loop or something that prints out, for example, "Mario" every second. How can I do this? Can't seem to find any good tutorials that teach this anywhere =P

推荐答案

可以使用java.util.Timer.

You can use java.util.Timer.

new Timer().scheduleAtFixedRate(task, after, interval);

task 是您要执行的方法,after 是距离第一次执行的时间量,interval 是上述任务执行之间的时间.

task is the method you want to execute, after is the amount of time till the first execution and interval is the time between executions of aforementioned task.

相关文章