Check this key [DFDEES3]. I haven't commented the code but what it does is store the state of the animation (And using the button constants to use the same states of the buttons) and play the animation if the state change. Also, call vsync once per cycle (After doing all the changes on the screen).