Virtual Dice tutorial


#1

I made a real simple Virtual Dice app.

You can extend the app if you like. Pressing the buttons or shaking the phone rolls the dice. There is no animation to see when rolling the dice but that could be added if you wanted. I just kept it simple.

VirtualDice.aia (99.0 KB)


#2

Thanks for sharing @Peter


#3

Very kind of you, @Peter
If we want use animation, i guess we need to use some frames like in your CoinFlip tutorial, right?


#4

Yes that could do it.


#5

Can you add animation to this. it will be really cool.


#6

Why not try yourself?


#7

I allowed myself to modify this code a bit, adding dices animations.
I hope Peter you will not be mad at me;)

Add a 3x Clock and call it:

  1. Roll_time : TimerAlwaysFires - uncheck, TimerEnabled - uncheck, TimerInterval - “10”.
  2. Roll_dice1_visual : TimerAlwaysFires - uncheck, TimerEnabled - uncheck, TimerInterval - “20”.
  3. Roll_dice2_visual : TimerAlwaysFires - uncheck, TimerEnabled - uncheck, TimerInterval - “20”.

And set the blocks as per the screenshot:


#8

For the animation, you can simply make a clock that repeats the dice throwing process many times, and when the clock stops, get the last number you got and that’s the final number. It might even add some more randomness like in a real life shaking!
Also, to add a cool effect, use the rotation property of the image component, so the dice will look like they were thrown on the table and they fell in a random angle.