iDevGames Forums
Attempting to add landscape IB buttons to an openGL View - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: Attempting to add landscape IB buttons to an openGL View (/thread-8214.html)



Attempting to add landscape IB buttons to an openGL View - Madrayken - Oct 15, 2010 10:43 AM

Hi folks,

I've written too much of my own GUI code over the last few months and decided to bite the bullet. It's time to add some UIKit stuff over the top of my lovely landscape openGL screen.

I've looked at 2 ways of doing this:-

- Adding a view controller and making the EAGL view a sub-view of it
- NOT adding a Simply adding buttons over the top of the EAGL view

I've tried the former and have had no success in getting the text buttons to display in Landscape format.

Any suggestions?
1) How would you best add gui buttons to an EAGLView based app without destroying frame-rate? (Note: I'm not asking for help with my current frame rate - it's great at the moment as I've done everything correctly. These additional buttons will only be displayed when choosing options, and then disappear).

2) How do you get IB created buttons to understand that you've defaulted to a landscape screen. IB is allowing me to change the ViewController to landscape, and draws the buttons nice and side-on. This is then completely ignored when actually creating the buttons at runtime.

Any help much appreciated. If I don't figure this out soon I'll just end up making my own GUI... again (I've been doing this a while, so this'll be about my 6th GUI).


RE: Attempting to add landscape IB buttons to an openGL View - iamflimflam1 - Oct 17, 2010 07:03 AM

To get the standard automatic support for different orientations you need to use a UIViewController and override the shouldAutorotateToInterfaceOrientation method to return true for landscape orientations.

This will apply the appropriate transforms to your view.

[/code]However, from what I understand there were/are? some performance implications of having your EAGLView transformed in this way.

If you are only supporting one landscape orientation then you can just manually add a transform to your button views to get them to appear in the right place. I'd suggest adding UIView on top of your EAGLView and then add the buttons to that. You can then just transform the UIView as required to get it into landscape mode.

If you want to support all the orientations then you can you can do this:
Code:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:UIDeviceOrientationDidChangeNotification object:nil];
and then you'll get notifications when the device orientation changes
Code:
-(void) orientationChanged {
    UIDeviceOrientation deviceOrientation=[UIDevice currentDevice].orientation;
    .. manually transform your views ...
}

You don't need a view controller for this to work - but you will get all the device orientations (including face up, face down etc...) not just portrait/landscape.