iPhone Gaming Framework: Amendment

Its been great to see a lot of you take apart the code and really see what you can do! There have been several people who have been in contacts with me via email, trying to get everything up and running.. but as you may have known, there are a few things missing from the tutorials. This is the amendment, going to patch up the final few things to get you back on track!

First thing is in the GLView.m file. We have a screen manager, but we are not telling the game to update or draw through the screen manager. Lets fix that! Go into your -(void)drawView method, and right below the glBindFrameBufferOES() call, you should have a [controller drawView:self]; … we’re going to change that to the following:

	//
	//	Update the view
	//
	[controller updateView:self WithTime:(float)[animationTimer timeInterval]];	
	//
	//	Draw the view
	//
	[controller drawView:self WithTime:(float)[animationTimer timeInterval]];

You’re going to call the controllers updateView and drawView methods, and pass in a time interval from the animationTimer. Now the controller will update and draw the game screens!

Secondly, There were a few people who never added a blankTexture to their project. I suggest opening an image editor, creating a black image called “blankTexture.png” and drag it into your resources file. You’ll notice, in the loadContent method, the screen manager allocates memory for the input manager, sets landscape mode, and then right after that loads in a blankTexture.png. If it doesn’t have one, it can’t load it.

Next amendment is more of a “clean up” since I didn’t fully understand how the retain / release system worked (Hey! i’m still a new mac developer too! :D ) In your addScreen method, you don’t need a [screen retain] since adding it to the screens NSMutableArray will retain the object. Likewise in the releaseScreen method, you’ll need to take out the [screen release] unless you like having your game crash when releasing a screen that has already been deallocated :)

With everything working, you’ll notice that your textures are being drawn “upside down” … well since we changed the way the coordinate system worked, and Apples “Texture2D” class works with the previous coordinate system, that will need to be changed. There are a few ways to do this; some people who really know their OpenGL suggested to flip the image before binding it.. the approach I took was just to adjust the vertices in the Texture2D draw methods.

This goes into your “drawAtpoint” method, comment out the current array:

	//
	//	Modified by Craig Giles to flip the texture upside down while using my coord system
	//    
	GLfloat		vertices[] = 
	{	
		-width / 2 + point.x,	height / 2 + point.y,	0.0,
		width / 2 + point.x,	height / 2 + point.y,	0.0, 
		-width / 2 + point.x,	-height / 2 + point.y,	0.0,
		width / 2 + point.x,	-height / 2 + point.y,	0.0
		
	};

This goes into your “drawAtRect” method, comment out the current array:

	//
	//	Modified by Craig Giles to flip the texture upside down while using my coord system
	//
	GLfloat	vertices[] = 
	{
		rect.origin.x,							rect.origin.y + rect.size.height,		0.0,
		rect.origin.x + rect.size.width,		rect.origin.y + rect.size.height,		0.0, 
		rect.origin.x,							rect.origin.y,							0.0,
		rect.origin.x + rect.size.width,		rect.origin.y,							0.0
		
	};

I think thats all the changes. Thanks again for everyones feedback on the last few writeups! I am looking over a few documents sent to me about templates, so I can release this as a starting template. Will let everyone know more when I can! As always, feel free to email me or post a comment if you need help with something.

5 comments so far

  1. nexus6 on

    @Craig
    Hi craig, thanks a lot for tutorial. The problem I have is the cdoe when compile without errors in SDK 3.0, it actually crashes if you click the background. Is there a patch that fixes this?

    Thanks.

    • Craig on

      I have not had the chance to look into the 3.0 SDK yet, but as soon as I am able to download and test my projects with it, I will attempt to make any changes and adjust the code.

      The error is: reason: ‘*** Collection was mutated while being enumerated.’ which, to me, means that the culprit is probably how the screen is being removed from the MutableArrays. When does it crash? before anything gets rendered to screen? or when you touch the screen (attempting to add or remove a screen from the array?)

  2. nexus6 on

    @craig
    Sorry, I forgot to mention that I am using the Template you created..

  3. nexus6 on

    @Craig
    Here’s a debug output, I hope this helps

    The Debugger has exited with status 0.
    [Session started at 2009-06-06 17:42:59 -0400.]
    2009-06-06 17:43:07.438 SeaDogs[1556:20b] Screen retain count: 1
    2009-06-06 17:43:16.339 SeaDogs[1556:20b] Screen retain count: 1

    [Session started at 2009-06-06 17:43:28 -0400.]

    [Session started at 2009-06-06 17:44:12 -0400.]
    2009-06-06 17:44:19.507 SeaDogs[1646:20b] Screen retain count: 1
    2009-06-06 17:44:19.509 SeaDogs[1646:20b] *** Terminating app due to uncaught exception ‘NSGenericException’, reason: ‘*** Collection was mutated while being enumerated.’
    2009-06-06 17:44:19.509 SeaDogs[1646:20b] Stack: (
    807902715,
    2529345083,
    808277198,
    22472,
    12662,
    810767821,
    807687328,
    807683624,
    839199793,
    839199990,
    814751534,
    9834,
    9710
    )

  4. nexus6 on

    Hi Craig,
    Yes, its when you touch the screen to go back it crashes


Leave a comment