A user was recently asking us about how to create dice in EveryGame, so I thought I'd share my response with everyone, since there's certainly lots of games that need them!
The simplest dice would look like this (a 6-sided piece, with a tap action to pick a random side):
<single_tap action="random_side" args="v2,0_1_2_3_4_5">
<sides paths="game_1.png,game_2.png,game_3.png,game_4.png,game_5.png,game_6.png>
<piece>dice</piece>
</sides>
</single_tap>
It can be hard for that simple case to see if when you tap, you've rolled the same value, or just missed. People have come up with a few solutions. One is to use two pieces, one with sides, and one always blank (to represent the "ready to roll" state). Each tap will flip between these.
<initial_location name="dice_location">
<single_tap action="send_to_back">
<sides paths="game_1.png,game_2.png,game_3.png,game_4.png,game_5.png,game_6.png>
<piece>dice</piece>
</sides>
<single_tap>
<single_tap action="send_to_back">
<single_tap action="random_side" args="v2,0_1_2_3_4_5,dice">
<sides paths="game_blank.png>
<piece>dice_blank</piece>
</sides>
</single_tap>
</single_tap>
</initial_location>
When the blank piece is on top, tapping it will send it to the back of the stack (hiding it), and roll the dice. When the dice is tapped, it's sent to the back, showing the blank piece.
If you want an example of the fancier setup, I suggest you look in the backgammon game's xml file. You could even use its dice images if you want.
If you are playing with multiple dice, you can setup the dice like mentioned and create one more piece that rolls them all:
ReplyDeletehttp://pastie.org/1117838