Requirement
Create flip effect on ImageButtons : When play button is touched, the menu buttons (achievement, leader-board, sound and in-app purchase buttons) should flip-out to become blank tiles and the game-mode(x5, x7 and hex) buttons should flip-in from blank tiles. Play button changes into 'back' button and when 'back' button is touched, game-mode buttons should flip-out and menu buttons should flip in.
Solution
Create two ObjectAnimator for each ImageButton to be flipped, one which animates the rotation around Y axis from 0 to 90 and another from 90 to 180 around Y axis.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ImageButton leaderBoard = (ImageButton) this.findViewById(R.id.MenuLeaderboard); | |
ObjectAnimator board_flip_0_90 = ObjectAnimator.ofFloat(leaderBoard,View.ROTATION_Y, 0,90); | |
ObjectAnimator board_flip_90_180 = ObjectAnimator.ofFloat(leaderBoard,View.ROTATION_Y, 90, 180); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This function first rotates the tile from 0 to 90 degree and then changes the image of the tile | |
and then rotates it from 90 to 180. This gives the effect of flipping a tile with two faces. | |
Here the flipOutLeaderboard() flipsOut the side with icon and flips in the gray tile. | |
flipInLeaderboard() flipsout the gray side and flips in the side with icon. | |
*/ | |
public void flipOutLeaderboard(){ | |
board_flip_0_90 .start(); | |
ImageButton leaderBoard = (ImageButton) this.findViewById(R.id.MenuLeaderboard); | |
leaderBoard.setImageResource(R.drawable.gray_tile); | |
board_flip_90_180 .start(); | |
} | |
public void flipInLeaderboard(){ | |
board_flip_90_180.reverse(); | |
ImageButton leaderBoard = (ImageButton) this.findViewById(R.id.MenuLeaderboard); | |
leaderBoard.setImageResource(R.drawable.rank_tile); | |
board_flip_0_90.reverse(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This method is called when onClick is triggered for the play/back ImageButton. The playVisible is set to true in onCreate method. | |
*/ | |
public void showModes(View button){ | |
if(playVisible){ | |
flipOutLeaderboard(); | |
playVisible = false; // play side of the tile is not visible | |
}else{ | |
flipInLeaderboard(); | |
playVisible = true; // play side is visible | |
} | |
} |
No comments:
Post a Comment