3D Dice Simulator



Silverlight 3D Dice User Control

The dice (shown above) are implemented as a Silverlight user control. You can include this in your own project by adding a reference to the DLL (see downloads below) and modifying the XAML to include the namespace, like this:

    xmlns:dice="clr-namespace:Dice3D.Silverlight.DiceUserControl;assembly=Dice3D.Silverlight.DiceControl"

Then when you add the control in the body of the XAML, select the number of dice and dice colours, the container material, the width and height of the control, and other settings:

    <dice:DiceControl
        Name="diceControl"
        Background="Transparent"
        Width="700"
        Height="320"
        Margin="20"
        NumDice="8"
        MaxDice="8"
        ContainerType="Large"
        DrawContainer="True"
        ContainerMaterial="Baize"
        DiceColor="Red"
        SpotColor="White"
        SpotSize="Medium"
        SoundOn="True"
        Click="diceControl_Click"
        DiceRollComplete="diceControl_DiceRollComplete"  
    />

(It is now also possible to specify any RGB colour for the dice, as well as different colours for different dice. It is even possible to use your own images. All this is configured in the XAML - see the example project for more information.)

Then in the code for the page, call the dice control's Roll() method to roll the dice:

    this.diceControl.Roll();

and also handle the DiceRollComplete event:

    private void OnDiceRolled(object sender, DiceRollCompleteEventArgs e)
    {
        // e.RolledTotal contains the total score rolled
        // e.RolledValues is an array containing the scores rolled on the individual dice
    }

The user control works in Silverlight 4 and above. It uses my own home-made 3D library since there's no built-in support for 3D in Silverlight 4.

Downloads

This example project is a basic skeleton project that includes the dice:

Play icon Silverlight 3D Dice Game Template Project

This example project shows the use of mouse events, e.g. clicking on dice:

Play icon Silverlight 3D Dice Click Events Demo Project

This project shows the dice control being used in a complete game:

Play icon Katego - Complete Game Example project

Comments (43)

skip to comment form

Marc Vandeputte
24/01/2011

Ed Smale
24/01/2011

wp7ericmswong
13/02/2011

ZhanSh
19/02/2011

Ed Smale
24/02/2011

Zlatko
17/03/2011

Ed Smale
28/03/2011

Zlatko
29/03/2011

Ed Smale
08/04/2011

wp7ericmswong
25/05/2011

AMiNE
12/08/2011

Ed Smale
16/08/2011

AMiNE
19/08/2011

Ed Smale
20/08/2011

AMiNE
27/08/2011

Jim
19/11/2011

Jim
22/11/2011

Ed Smale
23/11/2011

David
22/01/2012

Ed Smale
24/01/2012

David
28/01/2012

Ed Smale
31/01/2012

Michael
03/04/2012

Ed Smale
05/04/2012

Roman
23/04/2012

Ed Smale
23/04/2012

Alan
22/05/2012

Ed Smale
22/05/2012

Renish
11/07/2012

Tuuguu
26/07/2012

Ed Smale
04/09/2012

Maarten
18/10/2012

Ed Smale
20/10/2012

Maarten
22/10/2012

Ed Smale
23/10/2012

Ed Smale
28/10/2012

great work Ed
07/01/2013

Ed Smale
10/01/2013

siva
10/06/2013

Mark
22/01/2014

Smithk392
17/06/2014

kevinb
10/07/2014

kevinb
16/07/2014

Add a comment




3D Dice XNA Game Component

Eight red and blue dice in a baize container Eight black and white dice in a wooden container Four red dice in a marble container Eight black and white dice in a wooden container Four yellow dice in a 'grid' container

This is an XNA game component for 3D dice animation, featuring smooth animation and sound effects.

To create a game based on this dice component, first, declare an instance of DiceComponent in your game class:

    private DiceComponent diceComponent;

Then instantiate and configure the game component like this:

    this.diceComponent = new DiceComponent(this, 4)
        .SetNumDice(4)
        .SetDiceColors(Color.Red, Color.Blue)
        .SetSpotColors(Color.White)
        .SetSpotSize(DiceSpotSizeEnum.Large)
        .SetContainerMaterial(ContainerMaterialEnum.Wood)
        .SetContainerType(ContainerTypeEnum.Large)
        .SetCameraPosition(CameraPositionEnum.Side)
        .SetMakeSounds(true)
        .SetCameraFollow(true)
        .SetDrawContainer(true)
        .SetLeft(0)
        .SetTop(20)
        .SetWidth(1200)
        .SetHeight(600)
        .SetDiceRollComplete(this.OnDiceRollComplete);

All of the above .SetXXX() calls are optional - if a parameter is not configured, a default value will be used.

It is also possible to specify any RGB colour for the dice, as well as different colours for different dice. It is even possible to use your own images. This is configured via the SetDieFaceTextures() method - see the example project for more information.

Register the component in the game's Initialize() method:

        protected override void Initialize()
        {
            this.Components.Add(this.diceComponent);

            base.Initialize();
        }

Add the event handler OnDiceRollComplete (specified in the SetDiceRollComplete() method call above):

        public void OnDiceRollComplete(object sender, DiceRollCompleteEventArgs e)
        {
            // e.RolledTotal contains the total score rolled
            // e.RolledValues is an array containing the scores rolled on the individual dice
        }

Then to roll the dice, call the dice component's Roll() method:

    this.diceComponent.Roll();

Downloads

This example project is a basic skeleton project that includes the dice:

Play icon XNA 3D Dice Game Template Project

Add a comment




3D Dice Windows Phone / XNA Game Component

This is a WP7 / XNA game component for 3D dice animation, featuring smooth animation and sound effects.

Here are some screenshots:

Six black and white dice in a wooden container Four red dice in a baize container Six red dice in a leather container Six red and white dice in a granite container Four red and blue dice in a marble container Six yellow dice in a 'grid' container

To create a game based on this dice component, first, declare an instance of DiceComponent in your game class:

    private DiceComponent diceComponent;

Then instantiate and configure the game component like this:

    this.diceComponent = new DiceComponent(this, 2)
        .SetNumDice(2)
        .SetDiceColors(Color.Red, Color.White)
        .SetSpotColors(Color.White, Color.Black)
        .SetSpotSize(DiceSpotSizeEnum.Large)
        .SetContainerMaterial(ContainerMaterialEnum.Wood)
        .SetContainerType(ContainerTypeEnum.Small)
        .SetCameraPosition(CameraPositionEnum.Overhead)
        .SetMakeSounds(true)
        .SetCameraFollow(false)
        .SetDrawContainer(true)
        .SetLeft(0)
        .SetTop(220)
        .SetWidth(480)
        .SetHeight(480)
        .SetDiceRollComplete(this.OnDiceRollComplete);

All of the above .SetXXX() calls are optional - if a parameter is not configured, a default value will be used.

It is possible to specify any RGB colour for the dice, as well as different colours for different dice, using SetDiceColors() and SetSpotColors(). It is even possible to use your own images, using the SetDieFaceTextures() method - see the example project for more information.

Register the component in the game's Initialize() method:

        protected override void Initialize()
        {
            this.Components.Add(this.diceComponent);

            base.Initialize();
        }

Add the event handler OnDiceRollComplete (specified in the SetDiceRollComplete() method call above):

        public void OnDiceRollComplete(object sender, DiceRollCompleteEventArgs e)
        {
            // e.RolledTotal contains the total score rolled
            // e.RolledValues is an array containing the scores rolled on the individual dice
        }

Then to roll the dice, call the dice component's Roll() method:

    this.diceComponent.Roll();

Downloads

This example project is a basic skeleton project that includes the dice:

Play icon Windows Phone 3D Dice Game Template Project

Add a comment





More Info