Skip to content

Instantly share code, notes, and snippets.

@thesven
Created March 17, 2012 01:25
Show Gist options
  • Save thesven/2054145 to your computer and use it in GitHub Desktop.
Save thesven/2054145 to your computer and use it in GitHub Desktop.
PlayN Timer
package com.thesven.game.core.time;
import static playn.core.PlayN.*;
import playn.core.util.Callback;
public class Time {
public boolean running = false;
private double startTime;
private double elapseTime;
private double endTime;
private Callback<String> timerCallback;
public Time(double waitTime, Callback<String> callback) {
elapseTime = waitTime;
timerCallback = callback;
}
public void start(){
startTime = currentTime();
endTime = startTime + elapseTime;
running = true;
}
public void update(float delta) {
if(running){
if(currentTime() >= endTime){
running = false;
timerCallback.onSuccess("Time has elapsed");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment