iPhone Game Scoreboard using Core Animation
I have been helping out recently with a project running between UCLAN and Lancaster University which involves two teams of students working together to create a couple of iPhone games.
Last week one of the teams raised a question about how to create a rolling score board and we worked through a couple of ideas with some sample code but did not implement it fully. The idea stuck in my mind all week though and so in a little free time this morning I felt inspired to knock something together around it and this is what dropped out of Xcode at the end of it.
It has been implemented as a simple CALayer subclass that takes care of all of the management of the internal layers and animations and exposes a very simple interface to set the score value.
The images must be named 0.png through 9.png and included in the resources bundle but as long as you do that it should cope with any sized images as long as they are all the same size. The code can be found on github.
UPDATE: Thanks to John McKerrell for the suggestion that to give a little more realism, digits should transition in from the bottom coming from a lower number and in from the top from a higher number. This needed a bit of a hack around the 0/9 boundary but I think the outcome is pretty good. This is how it looks.
This was also a nice break from writing code on large projects, I have been really slacking on writing any code that isn’t going into a shipping codebase recently and so this was a very refreshing little break from the grind.
Looks snazzy, shouldn’t the numbers go backwards when the score goes down, or something like that?
I did play with having long strips of numbers backing each digit in the dial and moving them up and down so it was more realistic but it just didn’t look right because the timings were all funky when doing significant changes (ie. anything other than ±1) to the score.
I have just played with doing a simpler version as you suggested and with a bit of a hack to cope with the 0/9 boundary, I think it looks pretty good! Thanks for the suggestion. Updating the post now with another video.
Nice quick work there Dave! Looks even better :-)