added .then function to tweens
This commit is contained in:
parent
2ac964feeb
commit
ca7a74f774
|
@ -11,7 +11,10 @@ public class TestNode extends BaseGame {
|
|||
sprite.setTexture(window.loadTexture("demoassets/test.png"));
|
||||
sprite.setPos(new Vec2f(100, 100));
|
||||
rootNode.add(sprite);
|
||||
sprite.tweenPos(new Vec2f(800, 400), 120).delay(600);
|
||||
sprite.tweenPos(new Vec2f(800, 400), 120).delay(60).then(() -> {
|
||||
System.out.println("yay! got there! now lets go home");
|
||||
sprite.tweenPos(new Vec2f(100, 100), 120);
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -4,18 +4,26 @@ public abstract class BaseTween {
|
|||
protected double progress;
|
||||
protected int startFrame;
|
||||
protected int endFrame;
|
||||
protected Runnable thenFunc;
|
||||
|
||||
public BaseTween() {
|
||||
progress = 0;
|
||||
thenFunc = null;
|
||||
}
|
||||
|
||||
public void setProgress(double progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public void delay(int frames) {
|
||||
public BaseTween delay(int frames) {
|
||||
startFrame += frames;
|
||||
endFrame += frames;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BaseTween then(Runnable func) {
|
||||
thenFunc = func;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected abstract void apply();
|
||||
|
|
|
@ -36,6 +36,9 @@ public class Tweener {
|
|||
}
|
||||
}
|
||||
for(var tween : toRemove) {
|
||||
if(tween.thenFunc != null) {
|
||||
tween.thenFunc.run();
|
||||
}
|
||||
tweens.remove(tween);
|
||||
}
|
||||
++currentFrame;
|
||||
|
|
Loading…
Reference in New Issue