本文整理汇总了Java中org.jsfml.system.Clock类的典型用法代码示例。如果您正苦于以下问题:Java Clock类的具体用法?Java Clock怎么用?Java Clock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Clock类属于org.jsfml.system包,在下文中一共展示了Clock类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.jsfml.system.Clock; //导入依赖的package包/类
public static void main(String[] args) {
// Create a simulation.
Sim simulation = new Sim(WIDTH, HEIGHT, TITLE);
simulation.init();
// FPS/ticks count.
int ticks = 0;
int frames = 0;
Time fpsTime = Time.ZERO;
//Main loop
Clock clock = new Clock();
Time elapsed = Time.ZERO;
Time frameTime = Time.ZERO;
int skippedFrames = 0;
boolean hasFocus = true;
while(simulation.getWindow().isOpen()) {
frameTime = clock.restart();
elapsed = Time.add(frameTime, elapsed);
// Update 60 times per seconds
while(Time.ratio(elapsed, TIME_PER_TICK) >= 1.f && skippedFrames < MAX_SKIPPED_FRAMES) {
elapsed = Time.sub(elapsed, TIME_PER_TICK);
skippedFrames++;
// Handle events
for(Event event : simulation.getWindow().pollEvents()) {
if(event.type == Event.Type.CLOSED) {
simulation.getWindow().close();
}
else if(event.type == Event.Type.GAINED_FOCUS) {
simulation.onGainFocus();
}
else if(event.type == Event.Type.LOST_FOCUS) {
simulation.onLostFocus();
}
else if(event.type == Event.Type.KEY_PRESSED && event.asKeyEvent().key == Keyboard.Key.ESCAPE) {
simulation.getWindow().close();
}
else if(hasFocus) {
simulation.handleEvent(event);
}
}
// Update
simulation.update(TIME_PER_TICK);
// Tick count.
ticks++;
}
simulation.render(elapsed);
frames++;
skippedFrames = 0;
// Compute average FPS and display it in the window's title.
fpsTime = Time.add(frameTime, fpsTime);
if(fpsTime.asSeconds() > 1f) {
fpsTime = Time.sub(fpsTime, Time.getSeconds(1.0f));
simulation.getWindow().setTitle(TITLE + " | Ticks : " + ticks + ", FPS : " + frames);
// Reset counters.
ticks = 0;
frames = 0;
}
}
}