Advice regarding Views & Touches for iPhone game

Member
Posts: 48
Joined: 2009.05
Post: #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
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #2
Most games use a single OpenGL ES view, and that's it (at least for the "in game" parts). You then handle the raw touches and draw frames as needed. This scales much better as you add complexity but it might be more difficult to get started especially if you're used to using UIKit/Interface Builder.
Quote this message in a reply
Member
Posts: 48
Joined: 2009.05
Post: #3
Thanks Frank.

So in that case, is there a good tutorial for that? Because all 3 books are doing it with the multiple UIView method.

And what is the downside of having the 'virtual controls / buttons / on-screen joystick' handled in UIView's and the 'proper game' handled in an EAGLView?

'cause I'm thinking that buttons / joystick movements are just sprites....
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #4
If I bought a book called "iPhone Game Development" and it told me to stack UIViews for every game element I'd ask for a refund Annoyed

Here's a couple OpenGL ES tutorials (lots more via Google):
http://web.me.com/smaurice/AppleCoder/iP...chive.html
http://iphonedevelopment.blogspot.com/20...le-of.html

Apple also provides an OpenGL ES template project and several examples. And seriously, read Apple's documentation and technotes and examples and everything. I always find it odd that people scramble for 3rd party books before really digging into the official docs - there's craploads of good info in there...

I won't lie to you - if you don't have experience with OpenGL you'll might find this overwhelming at first but you'll be happier in the long run. There are also some free/opensource OpenGL ES iPhone game engines out there if you don't want to handle everything from scratch - Again, Google is your friend.
Quote this message in a reply
Member
Posts: 48
Joined: 2009.05
Post: #5
Hi

I'm fine with OpenGL on the PC Desktop - this is my first Mac anything project and it's for my MSc Dissertation - do an iPhone game and get it on app store in < 2 months and write 60000 words about it.

So I'm struggling to learn at the same time as doing - hence taking help from whereever I can get it.

I can google my ass off (and have) however, the fact remains that it's NOT opengl I'm having the problems with - it's how to use the right views and stuff to handle displaying the game in one view and player inputs on another... and how to handle the touch events for those.

None of that is anything I've found in either the official docs or anywhere else - hence looking at iPhone game specific books...

:/
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #6
Elphaba Wrote:I'm fine with OpenGL on the PC Desktop..

Then I'd recommended starting with Apple's OpenGL ES Template project. Read this to get a handle on Objective C: http://developer.apple.com/iphone/librar...tiveC.html

Don't worry about views and UIKit or Interface Builder. The EAGLView class in Apple's template is the only view you need to deal with. Also keep in mind that you don't need to use Obj-C for everything - 90% of my code is plain old C, so your OpenGL C/C++ skills will convert directly. You just need to know enough Obj-C concepts to understand how the OpenGL ES template project works, then call into your C/C++ functions in the appropriate spots.

Adding touch interaction isn't difficult - you can add the required delegates to the EAGLView class mentioned above then send off messages as needed to your C/C++ code. Here again Apple's docs and sample code are plenty good to get you going.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  detecting 2 touches, is order of touch significant? sefiroths 4 9,835 Sep 30, 2011 07:29 AM
Last Post: @iOS_blog
  Using Multiple Views Jerm #1 1 2,380 Feb 4, 2010 05:26 AM
Last Post: maximile
  Multiple Views MacSteve85 0 1,641 Feb 1, 2010 05:53 PM
Last Post: MacSteve85
  HUD - matching touches to object? cool mr croc 13 5,789 Aug 31, 2009 12:50 PM
Last Post: cool mr croc
  Navigation of views in view base application trygametest 0 2,139 Feb 20, 2009 06:12 AM
Last Post: trygametest