Add offset properties to Simple and Random Animations Runners
This commit is contained in:
@@ -34,6 +34,9 @@ public class RandomAnimationsRunner implements AnimationRunner {
|
|||||||
private float rotation = 0f;
|
private float rotation = 0f;
|
||||||
private RealDistribution rotationDistribution;
|
private RealDistribution rotationDistribution;
|
||||||
|
|
||||||
|
private float offsetX = 0;
|
||||||
|
private float offsetY = 0;
|
||||||
|
|
||||||
public RandomAnimationsRunner(int count) {
|
public RandomAnimationsRunner(int count) {
|
||||||
this.count = max(count, 0);
|
this.count = max(count, 0);
|
||||||
}
|
}
|
||||||
@@ -119,15 +122,21 @@ public class RandomAnimationsRunner implements AnimationRunner {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RandomAnimationsRunner offset(float x, float y) {
|
||||||
|
this.offsetX = x;
|
||||||
|
this.offsetY = y;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(Context context, Layer layer, Vector2fc origin) {
|
public void run(Context context, Layer layer, Vector2fc origin) {
|
||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < count; ++i) {
|
||||||
var animation = context.createAnimation(animationUids.get(random.nextInt(animationUids.size())));
|
var animation = context.createAnimation(animationUids.get(random.nextInt(animationUids.size())));
|
||||||
|
|
||||||
if (rangeDistribution != null) {
|
if (rangeDistribution != null) {
|
||||||
animation.setPosition(origin.x() + (float) rangeDistribution.sample(), origin.y() + (float) rangeDistribution.sample());
|
animation.setPosition(origin.x() + (float) rangeDistribution.sample() + offsetX, origin.y() + (float) rangeDistribution.sample() + offsetY);
|
||||||
} else {
|
} else {
|
||||||
animation.setPosition(origin.x() + rangeX, origin.y() + rangeY);
|
animation.setPosition(origin.x() + rangeX + offsetX, origin.y() + rangeY + offsetY);
|
||||||
}
|
}
|
||||||
|
|
||||||
animation.setScale(scaleDistribution != null ? (float) scaleDistribution.sample() : scale);
|
animation.setScale(scaleDistribution != null ? (float) scaleDistribution.sample() : scale);
|
||||||
|
|||||||
@@ -15,9 +15,11 @@ public class SimpleAnimationRunner implements AnimationRunner {
|
|||||||
private float speed = 0.05f;
|
private float speed = 0.05f;
|
||||||
private float rotation = 0f;
|
private float rotation = 0f;
|
||||||
private Path<Animation> path;
|
private Path<Animation> path;
|
||||||
private Integer pathRepeat;
|
private Integer repeatPath;
|
||||||
private boolean finishOnPathEnd;
|
private boolean finishOnPathEnd;
|
||||||
private boolean finishOnPathFail;
|
private boolean finishOnPathFail;
|
||||||
|
private float offsetX = 0;
|
||||||
|
private float offsetY = 0;
|
||||||
|
|
||||||
public SimpleAnimationRunner(String animationUid) {
|
public SimpleAnimationRunner(String animationUid) {
|
||||||
this.animationUid = animationUid;
|
this.animationUid = animationUid;
|
||||||
@@ -48,14 +50,29 @@ public class SimpleAnimationRunner implements AnimationRunner {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SimpleAnimationRunner speed(float speed) {
|
||||||
|
this.speed = speed;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public SimpleAnimationRunner rotation(float rotation) {
|
public SimpleAnimationRunner rotation(float rotation) {
|
||||||
this.rotation = rotation;
|
this.rotation = rotation;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleAnimationRunner path(Path<Animation> path, Integer repeat, boolean finishOnEnd, boolean finishOnFail) {
|
public SimpleAnimationRunner offset(float x, float y) {
|
||||||
|
this.offsetX = x;
|
||||||
|
this.offsetY = y;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleAnimationRunner repeatPath(int n) {
|
||||||
|
this.repeatPath = n;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleAnimationRunner path(Path<Animation> path, boolean finishOnEnd, boolean finishOnFail) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.pathRepeat = repeat;
|
|
||||||
this.finishOnPathEnd = finishOnEnd;
|
this.finishOnPathEnd = finishOnEnd;
|
||||||
this.finishOnPathFail = finishOnFail;
|
this.finishOnPathFail = finishOnFail;
|
||||||
return this;
|
return this;
|
||||||
@@ -64,7 +81,7 @@ public class SimpleAnimationRunner implements AnimationRunner {
|
|||||||
@Override
|
@Override
|
||||||
public void run(Context context, Layer layer, Vector2fc origin) {
|
public void run(Context context, Layer layer, Vector2fc origin) {
|
||||||
var animation = new DelayedAnimation(context.createAnimation(animationUid), delay);
|
var animation = new DelayedAnimation(context.createAnimation(animationUid), delay);
|
||||||
animation.setPosition(origin);
|
animation.setPosition(origin.x() + offsetX, origin.y() + offsetY);
|
||||||
animation.setScale(scale);
|
animation.setScale(scale);
|
||||||
animation.setAnimationSpeed(animationSpeed);
|
animation.setAnimationSpeed(animationSpeed);
|
||||||
animation.setSpeed(speed);
|
animation.setSpeed(speed);
|
||||||
@@ -72,7 +89,7 @@ public class SimpleAnimationRunner implements AnimationRunner {
|
|||||||
animation.setRepeat(repeat);
|
animation.setRepeat(repeat);
|
||||||
|
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
animation.followPath(path, pathRepeat, finishOnPathEnd, finishOnPathFail);
|
animation.followPath(path, repeatPath, finishOnPathEnd, finishOnPathFail);
|
||||||
}
|
}
|
||||||
|
|
||||||
layer.pushAnimation(animation);
|
layer.pushAnimation(animation);
|
||||||
|
|||||||
Reference in New Issue
Block a user