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

How can I do something every second? [LibGDX](我怎么能每秒都做某事?[LibGDX])

本文介绍了我怎么能每秒都做某事?[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.

这篇关于我怎么能每秒都做某事?[LibGDX]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:我怎么能每秒都做某事?[LibGDX]

基础教程推荐