OpenGL ES 2d game - multiple EAGL Views or not?

Posts: 48
Joined: 2009.05
Post: #1

I've been googling this one all morning.

Should I - for an iPhone game - use multiple EAGL views for each main GUI/Game element? i.e. an EAGLview for the main menu, one for say options, one for credits, one for 'level select', one for 'level loading' and one for 'main game'?


should I only have one EAGLview and do my own 'texture transitions' between them to move from one menu/game mode to another?

In particular, lets say I wanted to implement a slide/push view transition that I could do with UIKIT and Core Animation.

Would I do that with two EAGL views and use CA to do the push? Or should I stay with one EAGL view and 'emulate' the push with my own OpenGL routines?

Another part to this question becomes how to handle the touch routines for this. Because the touch events are handled INSIDE the EAGL view, then it might make more sense for different EAGLviews for each game element.

However, if I was to abstract the touch events out to a 'global' touch controller, that knew which game element or mode I was in (say main menu or options or game itself) then that could deal with the different contexts for a single touch event.

As usual I expect that i'm not making myself clear, so please feel free to ask me to clarify anything.

Thanks for your time.
Quote this message in a reply
Posts: 133
Joined: 2008.05
Post: #2
You want one EAGLView. You want to do any animations or transforms in your full screen EAGLView. (Read the OpenGL ES Programming Guide for the iPhone in the documentation.)

Also, you don't want your EAGLView to handle the touch events necessarily. You will want its view controller to handle touches. (A view's nextResponder is its view controller.)

What you really want in this situation is a view controller for each module of your game. Each of those view controllers' views will be that one instance of EAGLView. (edit: But not all at the same time!)
Quote this message in a reply
Posts: 283
Joined: 2006.05
Post: #3
If you want to use any of the UIViewController's design patterns (navigation, tabs etc.) I think it's worth using additional EAGL views and view controllers. This way you get standard behaviour for free. You also get the benefit of freeing up resources when you get a low memory warning, with very little additional effort.

But if you're after more customised behaviour, then it's probably faster, easier (but messier) to do it all yourself using just one GL view.

Edit: didn't think about using one view with multiple controllers.
Quote this message in a reply
Posts: 133
Joined: 2008.05
Post: #4
It is going to be a lot messier to use multiple GL views.

It is just as easy to implement freeing up resources in viewWillDisappear (as well as allocating resources in viewWillAppear) as it is to do that in viewDidUnload/viewDidLoad. In fact, you are better off being proactive and doing it in the appropriate methods than in a "last ditch" effort to reclaim memory.
Quote this message in a reply
Posts: 283
Joined: 2006.05
Post: #5
I was talking about UIViewController's default behaviour of responding to memory warnings by releasing its view if it's not visible. Keeps navigation quick when possible by keeping them in memory, but frees it up when it becomes a problem.

But yeah, I hadn't thought of using one view with multiple controllers. Never tried it, but it sounds like a good solution, and probably the right one in this situation.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Multiple XIB or Views Jerm #1 1 4,688 Feb 2, 2010 02:10 AM
Last Post: Newbrof
  Messaging between separate views Toontingy 0 3,040 Jan 9, 2010 05:10 PM
Last Post: Toontingy
  Downloading the same game multiple times EndeavorBros 0 3,614 Nov 17, 2009 12:57 AM
Last Post: EndeavorBros
  Logic Based Multiple View Game sum2cubes 1 3,765 Jul 2, 2009 08:30 AM
Last Post: bruss14
  Game, multiple object. explanation inside. natanavra 1 3,492 Apr 9, 2009 08:38 AM
Last Post: ThemsAllTook