Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile / iPhone

iPhone Gaming Framework: Amendment

5.00/5 (1 vote)
2 Jun 2009CPOL2 min read 18.8K  
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!

It's 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. Let's 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:

C++
//
//  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:

C++
//
//  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:

C++
//
//  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 that's 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.

Read original blog post here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)