Tutorial - How to make Tumbling Dice?

Tumbling Dice! It's the accelerometer-based app to test your luck! You can shake your phone to roll and rotate the dice! I have made this app as a tribute to the old version of the app in Bada OS v1.2, because I played with it a long time ago, and that time is long gone now. Well, I have made a new one!

Old Version (made in ActionScript Shockwave .swf) Tutorial (2022) Version

Now let's build the app! :wink:

First, we need to add a background to our screen.

Then we add a canvas and an Image sprite inside the canvas.

Capture2

Next, we add an Accelerometer sensor to our screen.

Capture3

Then we add all of our dice assets in the 'Media' section.

Capture4

Better name the dice assets from 1 -- 6 for programming more easily.


Blocks

Now let's code the app!

The critical part is that when we shake the phone, the dice will roll!

So, we use these blocks inside of the 'when AccelorometerSensor1.Shaking do' event.

The X property will change the dice's horizontal position by a random number from the canvas resolution. (0 -- canvas width or 295)

The Y property will change the dice's vertical position by a random number from the canvas resolution. (0 -- canvas height or 375)

The picture block will set a random dice picture from Dice 1 to 6. I used this approach for easier programming.

The Heading block will rotate the dice randomly at every angle.

You can add these similar blocks to the Screen1 initialization event as well!


Now it's up to you to modify this further!
TumblingDiceTest.aia (353.3 KB)

Add 2 more dices, change their modes, and do whatever is your imagination! Be creative!

Thanks, please click on the :heart: option as it really helps and supports me! Improvements are always welcome!

1 Like