public static Animator createRectangleAnimator(final RectangleSprite sprite, PreciseRectangle rectangle) {
final PreciseRectangle origin = new PreciseRectangle(sprite.getX(), sprite.getY(), sprite.getWidth(),
sprite.getHeight());
final PreciseRectangle delta = new PreciseRectangle(rectangle.getX() - sprite.getX(), rectangle.getY()
- sprite.getY(), rectangle.getWidth() - sprite.getWidth(), rectangle.getHeight() - sprite.getHeight());
return new Animator() {
@Override
protected void onUpdate(double progress) {
sprite.setX(origin.getX() + delta.getX() * progress);
sprite.setY(origin.getY() + delta.getY() * progress);
sprite.setWidth(origin.getWidth() + delta.getWidth() * progress);