I have some code which creates a list of points called path.
Here is a sample list: [[1, 3], [2, 3], [2, 4]]
Here is the code I wrote to animate movement to these points sequentially:
ArrayList<Animator> movements = new ArrayList<>();
int prevY = start[1];
int prevX = start[0];
for (int[] square : path) {
ObjectAnimator motion = new ObjectAnimator();
float[] coord = screenFromGrid(square[0], square[1], gridSizeY);
long speed = (long) (6000.0 / this.displayMetrics.widthPixels);
speed = (long) (speed * getSquareSize(gridSizeY));
if (square[0] != prevX) {
motion = ObjectAnimator.ofFloat(this.sprite1, "x", coord[0]);
motion.setInterpolator(new LinearInterpolator());
motion.setDuration(speed);
movements.add(motion);
prevX = square[0];
} else if (square[1] != prevY) {
motion = ObjectAnimator.ofFloat(this.sprite1, "y", coord[1]);
motion.setInterpolator(new LinearInterpolator());
motion.setDuration(speed);
movements.add(motion);
prevY = square[1];
}
}
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playSequentially(movements);
animatorSet.start();
The problem is that animation completely stops in the middle without throwing any error.
I checked the debugger and it says all the animations have been stored properly.
Does anyone know why this is happening?