Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-12-2012, 02:02 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 112
RoryHarvey is on a distinguished road
Default Best way to do buttons for an OpenGL ES iPhone game

I'm making a simple 2d game in OpenGL ES and I want to add movement buttons to it. What's the best way of going about this? In previous projects I've simply added UIButtons to the view but I hear there are performance implications in doing so with OpenGL ES so I'm wondering what the possible alternatives are if so.
RoryHarvey is offline   Reply With Quote
Old 01-12-2012, 02:49 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by RoryHarvey View Post
I'm making a simple 2d game in OpenGL ES and I want to add movement buttons to it. What's the best way of going about this? In previous projects I've simply added UIButtons to the view but I hear there are performance implications in doing so with OpenGL ES so I'm wondering what the possible alternatives are if so.
The simplest/cleanest way to handle this is probably to make your OpenGL view be part of the screen, in a rectangular area.

Create another view controller that manages your Cocoa controls.

Note that the new GLKViewController class added in iOS 5 insists that the view controller's entire content view be a single GLKView (OpenGL View)

You can either toss out the GLKViewController and add a GLKView to a regular view controller, or use the new child view controller facility in iOS 5 to make a GLKViewController manage your OpenGL view, and the parent view controller manage the Cocoa controls. (or make the parent view controller manage another child view controller with your controls on it. That can make for an elegant, modular design.)

For the work I've done so far, I've tossed the GLKViewController and managed a GLKView myself, but I spent a lot of time figuring out how to get a GLKView working by itself. (Mostly it was unfamiliarity with OpenGL ES 2 and it's requirement that you write a shader to do everything.)

Next time I tackle OpenGL in iOS, I will probably make the OpenGL part(s) of my screens be child view GLKViewController objects where the GLKView is the whole content of the GLKViewController, as Apple intends.

BTW, I've added a Cocoa touch button on top of a GLKView and did not notice a performance penalty. I only added a single button though, and did not use shadows, partial transparency, or any of those performance-killing options.

You might want to code it so you can put you buttons on top of your GLKview or not, depending on what you find in terms of performance. If you manage your OpenGL content using a GLKViewController, with the buttons hosted in another view controller, you can put your buttons on top of the OpenGL view or not, without having to make structural changes.

OpenGL development is all about performance testing and iterative development. You have to write something, see how it performs, and fine-tune as needed to get the performance you want/need.

Make sure you test on the oldest/slowest device you plan to support. We've decided to drop support for iOS < 5.0, so we've dropped the iPhone 3G and the equivalent iPod touch (2nd gen, I think it is.)

Requiring iOS 5 enables us to use all the cool new features like GLKit, parent/child view controllers, block-based animation, etc, etc. Big win.

The 3G has MUCH more limited graphics hardware, much less memory, and a much slower processor. It is a LOT harder to get acceptable performance from a 3G. It's also getting pretty old and out-of-date.

The 3Gs is actually a pretty decent performer, and there are apparently a lot of them out in the field. That's our base platform going forward.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 375
11 members and 364 guests
7twenty7, Atatator, glenn_sayers, guusleijsten, iphonedevshani, j.b.rajesh@gmail.com, QuantumDoja, sacha1996, Sami Gh, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:41 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0