63 lines
1.6 KiB
Java
63 lines
1.6 KiB
Java
/*
|
|
* Created by Julian Mutter on 7/10/18 3:58 PM
|
|
* Copyright (c) 2018. All rights reserved.
|
|
* Last modified 7/10/18 3:54 PM
|
|
*
|
|
*/
|
|
|
|
package de.frajul.endlessroll.entities;
|
|
|
|
import de.frajul.endlessroll.main.game.Timer;
|
|
|
|
/**
|
|
* Created by Julian on 14.12.2015.
|
|
*/
|
|
public class Animation {
|
|
|
|
private int[] indexSequence = {0, 1, 2, 3};
|
|
private boolean looping = false;
|
|
private int requiredDelta = 110;
|
|
|
|
private int indexPointer = 0;
|
|
private boolean stillRunning = true;
|
|
private long lastSwitchTime = -1;
|
|
|
|
public void disable() {
|
|
stillRunning = false;
|
|
}
|
|
|
|
public void update(Timer timer) {
|
|
if (lastSwitchTime == -1) {
|
|
lastSwitchTime = timer.getCurrentTime();
|
|
return;
|
|
}
|
|
if (stillRunning) {
|
|
long delta = timer.getCurrentTime() - lastSwitchTime;
|
|
if (delta >= requiredDelta) {
|
|
lastSwitchTime = timer.getCurrentTime();
|
|
indexPointer++;
|
|
if (!looping && indexPointer == indexSequence.length - 1)
|
|
stillRunning = false;
|
|
if (looping && indexPointer == indexSequence.length)
|
|
indexPointer = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
public int getCurrentTexIndex() {
|
|
return indexSequence[indexPointer];
|
|
}
|
|
|
|
public void setIndexSequence(int[] indexSequence) {
|
|
this.indexSequence = indexSequence;
|
|
}
|
|
|
|
public void setRequiredDelta(int requiredDelta) {
|
|
this.requiredDelta = requiredDelta;
|
|
}
|
|
|
|
public void setLooping(boolean looping) {
|
|
this.looping = looping;
|
|
}
|
|
}
|