I’m making available the sources for The Devil’s Dice available as sample code. You are free to peruse the code, build it, even grab classes from it to use as you see fit in your own applications. I only ask that you don’t submit it to the App Store as the Pig dice game that it is (feel free of course to write a slot machine app from it or whatever if you like).
The application uses simple UIView’s for “sprites” and CocosDenshion for the sound. All animation is done either implicitly by using CoreAnimation or through explicitly changing the bounds or alpha of individual UIViews. For an arcade game with dozens of sprites and a quick frame-rate, using UIViews wouldn’t suffice. But for a simpler “parlor game” like The Devil’s Dice, using UIViews or CALayers makes a lot of sense.
Nonetheless I have found that, even with CALayers, the moment you start trying to use transforms (scaling, rotating) the performance can suffer considerably. If you can stick to translation and alpha animation, UIView/CALayers work well.
Without a sprite engine the code remains easy to learn and easy to find your way around the project quickly.
I tried to use more of a vanilla approach to sounds, but the performance wasn’t there ... the animation in the game became jittery when the sounds were playing. CocosDenshion is an extremely simple sound engine that ships as part of Cocos2D and did the job admirably. When a sound fires off using CocosDenshion, no slow noticeable slowdown in the animation.
There are three view controllers. RootViewController is the primary controller — most of the game state machine and logic are in here. The PlayViewController is brought up to display the game stats and handling the “Player vs. Devil” and “Player vs Player” buttons. The InfoViewController displays the rules and sound volume setting.
Touches for the large red “roll lever” and smaller red “turn lever” are tracked in RootViewController. The info button (in the lower right above) is wired in the standard way through the NIB file. There are no other user-interactions for the RootViewController.
