views:

336

answers:

1

Hi

I've been reading three books (iPhone Game Development, iPhone cookbook and beginning iPhone development), but so far I've not found the answer to my question, so I was hoping someone here could help me.

As an example, lets say that I want to have a joystick onscreen, and three buttons.

I need all of these permanently visible on the bottom of the screen and not taking up any of the game rendering area i.e. not overlayed onto the game.

Ok?

Now, from what I can gather, one way to do this, if I've understood this correctly, is to break those FOUR controls, and put each one on it's OWN VIEW (OR SUB-VIEW), and have transparency where the other controls are on each layer...

So layer 1, will have the joystick and the background around the joystick, but a transparent section to the right of it...

the layer underneath that will be transparent where the (above layer) joystick is, and then have the bitmap for the button, and then transparent again to the right of that button... etc etc for each further layer / button.

That way I have a hierarchy for touch testing, if it's on a transparent area, send to the next sub-view.

However, by the time I've got the game rendering and the scores etc... I'm looking at about 7 views...

So my questions are these:

  1. Is this the best (optimal) way to do this? If not, then how?

  2. Is there a performance or SDK limit on View's with subviews or just multiple layers of views?

  3. Can all this be done on one layer / view =- bearing in mind that the joytick will move in all directions at the SAME TIME as one or MORE of the buttons can be pressed. therefore a false 'pinch' gesture could be detected by a button on the right of the screen being pressed at the same time the joystick is moved away from that finger press... see?

Please help, if you can.

If I've over complicated this, or got confused, please forgive me - I find it VERY difficult to 'teach' myself stuff... and if my explanations are confusing, please let me know and I'll try and rewrite them.

Thanks

+1  A: 

If I understand, you are asking the UIKit to do the compositing of your bitmaps in 7 overlapping views instead of compositing it yourself into 1 image in a view. You also get the “benefit” of passing clicks through a chain of command.

I would do it with one view – draw the bitmaps into one image each time there is a change - or even draw the joystick/button control bitmaps on top of the main graphics area. (You may also want to make the control size adjustable, and scale the images.)

Testing each click against the non-transparent area of each layer doesn’t seem any simpler than testing the click against the known rectangles of all controls in a single image. I would think this code would be clearer in the end – fewer objects.

As for “pinch”, the beginning point of the touch should determine which control is touched, and the touchesMoved data determines where it goes to. Don’t use the touchesMoved data to initiate a new button press.

That said, I do everything in OpenGL so I’m used to managing my own layers.

Erik Olson