Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

flummoxed

macrumors member
Original poster
Nov 27, 2010
38
0
I'm creating a simple slot machine game as an exercise to learn how to program different elements of the iPhone UI.

I have already succeeded in using the UIPickerView control divided into 3 columns, and applying icon images for the slot machine symbols onto each column reel. I can animate the columns, but since they all belong to a single pickerview they can only animate for the same duration.
So if they all start at the same time, they must stop at the same time, unlike a real slot machine in which the reels stop one at a time in sequence. The pickerview is somewhat restrictive.

In order to create a more realistic animation I will need to dispense with the UIPickerView and create my own UI out of individual UIView strips side by side.
I have at least 10 symbols per reel, and the reels need to spin for 3, 4, and 5 seconds. So that means drawing a multitude of repeated UIImageViews on each reel - as much as 80 UIImageViews on a reel.

My question is:

Is it more efficient and better for performance to recycle the same 10 imageViews as the strip moves through the viewport ,
or
simply create all 80 UIImageViews and not have to code the recycling of the views. It seems like creating so many repetitions of the same image is a waste of memory - even though the images are only around 9 -16 kb each.

I've tried to recycle the images as the strip moves but I can't get the code to work, so I'm thinking the simplest method is to just draw all the images and forget about it.

My main concern is for performance and efficiency.
 
One of the biggest programming mistakes is to worry about efficiency and optimization too early. Get it working first and then look for where the code is too slow. Often its in a completely different area than you think it is.
 
You might want to consider having three (single-component) UIPickerViews side-by-side.

Also, something to consider (and I can't remember where I came across this): A lot of the time the dial is spinning, you can't really tell what it's showing (i.e. it's just a blur). So, just animate a blur image (over top of the dial), and then only worry about scrolling the actual images when it starts to slow down (at which point you remove the blur).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.