Flash notes by Edzis

ActionScript programmer / Flash developer Edgars Simsons on professional stuff

3D dice with rounded edges

with 12 comments

3D Dice. Click to view in action

3D dice. Click to view in action

This is a 3D dice I made in FIVe3D. It has rounded edges that animates with rotation to the next score.

A couple of weeks ago I had to add a dice for a game my colleague was developing. Scanning the net did not give any satisfactory results so I set off to make it myself. As I knew there will be vectors only I chose to use this task to check out FIVe3D. After dropping the idea to implement real physics I made the first static dice rather fast -  just a cube with 6 faces and circles on them.  The sharp corners just did not fit the the design requirements. So in a dirty way I squeezed in some extra rectangles and triangles between the 6 faces of the cube what made the corners appear rounded. For the outlines see the image on the side. Sadly this broke the shadows being drawn correctly; I tried to overcome this problem but did not succeed  (but maybe someone else wants to try it out).

Outlines of the cube edges

Outlines of the cube edges

The dice is easily customizable. You can change it’s size, view angle and light effects. The dice’s roll() method accepts a previously chosen target value, but can generate it on random. An event is dispatched after the roll animation has completed. It has a slightly different animation depending on mouse position.

View the example and download project source. Let me know if you find it useful.

Written by edzis

March 13th, 2009 at 3:31 pm

Posted in ActionScript 3

12 Responses to '3D dice with rounded edges'

Subscribe to comments with RSS or TrackBack to '3D dice with rounded edges'.

  1. nice fav icon!

    Chris

    13 Mar 09 at 17:19

  2. Hi!
    First of all I want to congratulate you for the nice job you’ve done here.
    I was looking for something like this, and with your permission I would like to use for a small game I’m making for kids in a portuguese university.

    I’m trying to integrate this class in the game, wich I thought that would be easy, since it’s very simple, but it turns out that I’m having some difficulty doing it.

    I work also with FlashDevelop, and entered the classpath for Five3D that I download, and did the same with caurina. I instantiate the dice class and the following message apeears among others of the same type “1024: Overriding a function that is not marked for override.” in the Shape3D.as class in Five3D. Any ideia why this happens? If you wish you can send me a reply for my email.
    Thanks.

    Leonel

    27 Mar 09 at 12:06

  3. Glad to hear you want to use it. You surely have my permission.
    But for the bug it is strange. I tried downloading a new copy of Five3D and it works fine (after variable type declarations in Bitmap3D lines 401 and 402). I could not reproduce your problem.
    Bat can you locate which line in Shape3D is making this problem? So this is a compiletime or runtime error? Are you targeting flash player 9 or 10?

    edzis

    27 Mar 09 at 12:44

  4. Thanks! :)

    I’m targeting for Flash Player 10, and thse messages appeared on compiletime. Meanwhile I manage to solve those messages, since rotationZ and z function needed to be overrided since they exist also in flash classes (I wrote the “override” keyword on Bitmpa3D, Sprite3D and Sprite2D). For now these problems are no longer happening… other issues came along, like instantiating onde dice to appear inside a small “window”.

    I’ll send you the feedback of any problem, or if I manage to put this to work :)

    Leonel

    27 Mar 09 at 13:05

  5. HI again,

    I manage to set this working in the game, it’s spinning and sending the draw number… the result is very good, I must say… nice work :)

    Leonel

    27 Mar 09 at 15:19

  6. Hey;

    This script is cool and I would like to use it but I cant find the way to get it working
    Does anyone as a demo project I can open with CS3 so I can start from there.

    Thanks for your help; I dont know much about AS and stuff

    axe

    23 May 09 at 23:57

  7. hii

    Congratulations on your work is fantastic. I am still beginner in flash and i´m trying to use your code, but can you explain what i must do to make the flash file from the actionscript similar to yours? because I want to change somme things?

    thanks =)

    Bruno

    17 Jul 09 at 03:49

  8. where can i find the fla………

    amit

    18 Jan 10 at 13:50

  9. There is no .fla file. I have delivered this in the form of a pure code FlashDevelop (www.flashdevelop.org) project.
    If you wish to use it with Flash Professional I suggest creating a new fla in the project’s folder, adding “src” as the classpath and setting “com.edzis.DiceExample” as the document’s class.

    edzis

    18 Jan 10 at 14:13

  10. thanks man u r genius,,,,,,,

    amit

    18 Jan 10 at 14:26

  11. can i add movieclips add the faces

    sandy

    20 Jan 10 at 16:00

  12. thanks a lot for your help :) )

    NUMB

    8 Feb 10 at 10:39

Leave a Reply