How state-based animation works