added .then function to tweens

This commit is contained in:
DaniTheSkunk 2022-10-12 01:42:59 +00:00
parent 2ac964feeb
commit ca7a74f774
3 changed files with 16 additions and 2 deletions

View File

@ -11,7 +11,10 @@ public class TestNode extends BaseGame {
sprite.setTexture(window.loadTexture("demoassets/test.png")); sprite.setTexture(window.loadTexture("demoassets/test.png"));
sprite.setPos(new Vec2f(100, 100)); sprite.setPos(new Vec2f(100, 100));
rootNode.add(sprite); 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) { public static void main(String[] args) {

View File

@ -4,18 +4,26 @@ public abstract class BaseTween {
protected double progress; protected double progress;
protected int startFrame; protected int startFrame;
protected int endFrame; protected int endFrame;
protected Runnable thenFunc;
public BaseTween() { public BaseTween() {
progress = 0; progress = 0;
thenFunc = null;
} }
public void setProgress(double progress) { public void setProgress(double progress) {
this.progress = progress; this.progress = progress;
} }
public void delay(int frames) { public BaseTween delay(int frames) {
startFrame += frames; startFrame += frames;
endFrame += frames; endFrame += frames;
return this;
}
public BaseTween then(Runnable func) {
thenFunc = func;
return this;
} }
protected abstract void apply(); protected abstract void apply();

View File

@ -36,6 +36,9 @@ public class Tweener {
} }
} }
for(var tween : toRemove) { for(var tween : toRemove) {
if(tween.thenFunc != null) {
tween.thenFunc.run();
}
tweens.remove(tween); tweens.remove(tween);
} }
++currentFrame; ++currentFrame;