Advice regarding Views & Touches for iPhone game - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Advice regarding Views & Touches for iPhone game (/thread-996.html)
Advice regarding Views & Touches for iPhone game - Elphaba - Jul 17, 2009 07:15 AM
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.
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.
Advice regarding Views & Touches for iPhone game - Frank C. - Jul 17, 2009 12:00 PM
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.
Advice regarding Views & Touches for iPhone game - Elphaba - Jul 17, 2009 12:15 PM
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....
Advice regarding Views & Touches for iPhone game - Frank C. - Jul 17, 2009 01:28 PM
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
Here's a couple OpenGL ES tutorials (lots more via Google):
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.
Advice regarding Views & Touches for iPhone game - Elphaba - Jul 17, 2009 01:32 PM
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...
Advice regarding Views & Touches for iPhone game - Frank C. - Jul 17, 2009 01:54 PM
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/library/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.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.