org.pixel.commons.DeltaTime Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pixel-commons-linux Show documentation
Show all versions of pixel-commons-linux Show documentation
Java 2D Game Framework inspired on the popular XNA framework.
The newest version!
/*
* This software is available under Apache License
* Copyright (c) 2020
*/
package org.pixel.commons;
public class DeltaTime {
private long lastTimestamp;
private long elapsedMilliseconds;
private float elapsedSeconds;
/**
* Constructor
*/
public DeltaTime() {
this.lastTimestamp = System.nanoTime() / 1000000;
}
/**
* Get the elapsed time in seconds
*
* @return seconds
*/
public float getElapsed() {
return elapsedSeconds;
}
/**
* Get the elapsed time in milliseconds
*
* @return milliseconds
*/
public long getElapsedMs() {
return elapsedMilliseconds;
}
/**
* Update elapsed time (calculates delta since last tick)
*/
public void tick() {
long now = System.nanoTime() / 1000000;
elapsedMilliseconds = now - lastTimestamp;
elapsedSeconds = elapsedMilliseconds / 1000f;
lastTimestamp = now;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy