I am currently doing a beginners android studio/java course. I have made a Dice rolling app and a Magic Eight Ball app that both use an RNG and arrays to overlay new images on a button press.
After showing to friends, they have said it would be good to have some kind of animation, now I am not going to model and animate 3D dice etc, simply because I can't.
I did have the idea that pressing the button that fires the RNG could be used to fire it a set amount of times, lets say 10 as an example, and the resulting cycling through dice numbers/8ball images would give a pseudo animated appearance.
My question is, how do I make a single button press, fire the RNG/Array more than once?
I have tried to search an answer for this on here and google, but I do not think I am asking the right questions, as all the answers I can find are on how to stop multiple actions taking place, rather than trying to force them automatically
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button AskButton;
AskButton = findViewById(R.id.AskButton);
final ImageView Ball;
Ball = findViewById(R.id.Ball);
final int[] ballArray = {R.drawable.ball1,
R.drawable.ball2,
R.drawable.ball3,
R.drawable.ball4,
R.drawable.ball5};
AskButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("Magic Eight Ball", "Button Press");
Random RNG = new Random();
int number = RNG.nextInt(5);
Log.d("Magic Eight Ball", "Number is:" + number );
Ball.setImageResource(ballArray [number]);
}
});
}
}
Currently, one button press changes the image once, I want the one button press to change the image 10 times in quick succession before stopping.