计时器的正确用法
Introduction
之前一直想实现“技能冷却”效果,百度和论坛上一时间也搜不到什么好的方法,在宿舍和天花板交流了一会以后发现用一个简单的计时器即可。
To think of it
我要使用一个技能fff();这个技能需要放在一个布尔锁里,每当使用这个技能,就用一个计时器去控制布尔锁。
To do this
首先要引入Timer类,调用Timer里的schedule方法,这个方法需要引进一个TimerTask类参数,和下一次执行的时间。
运行环境:Processing-Java
|
|
运行结果
FFFFFF!
Fire is not prepared, please wait 5s.
Fire is not prepared, please wait 5s.
Fire is not prepared, please wait 5s.
Fire is not prepared, please wait 5s.
Fire is not prepared, please wait 5s.
Fire is not prepared, please wait 5s.
Fire is not prepared, please wait 5s.
Fire is not prepared, please wait 5s.
Fire is not prepared, please wait 5s.
FFFFFF!
Fire is not prepared, please wait 5s.
Fire is not prepared, please wait 5s.
Fire is not prepared, please wait 5s.
Fire is not prepared, please wait 5s.
Fire is not prepared, please wait 5s.
完美