Reputation: 45
I have created give a card animation in android. When I get response from server that I should run this animation. So in the beginning of the game I should give card to all players.
1) My first approach was just loop through players and run for each one giveCardAnimation,but then animations don't wait each other to finish
2) Second approach was using Handler inside for loop,but this works just one time in server I can sometimes get giveCardToAllPlayers 2 times. So this giveCardPlayer function should wait until animation is finished
Handler().postDelayed({
giveCardToPlayer(playerId)
}, duration * index)
How can I run this giveCardPlayer function again for the other players when animation is finished for one player?
Upvotes: 1
Views: 54
Reputation: 156
I think what you are looking for is onAnimationEnd() in AnimationListener , where your animation object takes an object which implements Animation Listener like this
animation.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationEnd(animation: Animation?) {
giveCardAnimationForNextPlayer()
}
override fun onAnimationStart(animation: Animation?) {}
override fun onAnimationRepeat(animation: Animation?) {}
}
Upvotes: 1