qq_tracker_code_advanced_default

How much time and effort would you say a typical developer puts into making a game? I can tell you from experience that if you are just one person, it can very well take months upon months to come up with a good game and maybe close to a year to come up with a great game.

If you’ve ever developed a great game or even just an average game, you should also know the value of having a free Lite Version for your paid Full Version. If your game requires a purchase of even .99 cents you should make sure that you provide users with a Lite / Trial Version of your game that they don’t have to pay for. The purpose of having a Lite Version is so that they can try out your game with the other reason being of course marketing.

Everyone will download the free version over the paid version so what you have to do is make sure that your free version leaves with some sort of cliff hanger, something that will make the user want to purchase your full version to continue playing. If you’ve ever watched a season of any TV show, you’ll see that at the end of the season it leaves you with a cliff hanger and by the time the new season comes on, you can hardly contain yourself. This is what your game should do, it should make the user curious about what comes next, what will happen to the hero at the end of the story???

Anyways, enough of that… let’s get on with the tutorial. I will be showing you how to implement within Xcode a really quick and easy method to keep your Full and Lite versions separate but together…

An overview of what we will be doing is outlined in the steps below:

  • Start a new XCode Project
  • Duplicate the current Target
  • Rename the Duplicated Target
  • Rename the Duplicated Info.plist File
  • Change the Icons in the Duplicated Info.plist file to use the Lite Version Icons
  • Change the Bundle Identifier to match with the bundle identifier from Apple for the Lite Version
  • Edit Build Properties of the Duplicated Target
    - Add C / C++ Compiler Flags
    - Change the Product Name
    - Change the name of the Info.plist file to the name of the Duplicated Info.plist File
  • Add Logic to code to separate features of Lite and Full version.

As you can see, in only a few steps we can set up our app’s environment to make it very easy to have a lite and full version within the same project and be able to build them separately. In the tutorial listed below I will be covering what I have outlined above with a lot more details and screen shots.

Let’s Start by Opening Xcode and starting a new project. I’ll be starting a new Cocos2D project as you can see in the Screen shot below and I’ll be calling it MyGame.

After you’ve started a new project and Xcode has finished loading you will need to look on the bottom left side of the window. You’ll need to locate and expand the Targets group and then right-click and click on duplicate. See the screen shots below for an example.

This will make a duplicate of the MyGame Target, and will also create a duplicate of the Info.plist file. Next we will need to rename the duplication of the MyGame Target. I’m going to use the name MyGameLite. We will also need to rename the duplicated Info.plist file, and for simplicity I just named mine InfoLite.plist, to keep a standard naming convention. You can see some example screenshots below.

You’ll also notice that in the above screen shot to the right clicking the Build drop down will now show you 2 Targets, one for MyGame and one for MyGameLite.

Next we need to edit some of the Build settings for the MyGameLite Target. If its not already expanded, expand the Targets group and then right click on the MyGameLite target and from the pop-up menu, click on Get Info. An example screen shot is shown below.

After clicking on Get Info, you will be presented with a dialog box that has a number of tabs across the top of it. The tab we are interested in is the build tab. Go ahead and click on the build tab and ensure that in the Configurations drop down, that All Configurations is selected, then in the Search window type Product Name. If you are following this tutorial to the T, then your product name should say MyGame. We’ll need to change that to MyGameLite. To change it, just double-click on MyGame and then make your change and click on OK. See example screen shots below.

Don’t close the Build Settings just yet, we have a few more steps to take before we’re done. In the search bar type. Other C. This should give you results similar to the screen shot below

What we are interested in here are the “Other C Flags” and the “Other C++ Flags”. Your results may differ from mine depending if you already have some compiler flags setup. Double click on the empty space next to Other C Flags and you will get a dialog window pop up. In this window you will need to type the following without quotes: “-DLITE_VER” and then click on OK. This should set both the “Other C Flags” and the “Other C++ Flags” See screen shots below for examples.

I know that the screen shots are a little small but if you click on them you can see the images a little bigger. There is one more setting that we need to change in the Build settings and that is to specify the name of our Info.plist file. Currently it is still defined as Info.plist but we want to set it to InfoLite.plist so that the build settings match.

Go ahead and type Info.plist File and locate the “Info.plist File” string which should read “Info Copy.plist” or something similar. Change this string to InfoLite.plist.

You are now done with Build settings and you can safely close the Build Settings Dialog. See below for some example screen shots for renaming Info Copy.plist

Now we just need to make a few minor changes to our InfoLite.plist file and then we can start modifying some code. Locate the InfoLite.plist file, usually in the left column under the Resources group and click on it. You should see the values of the InfoLite.plist file listed in your preview window on the bottom right.

We need to change the Icon and the Bundle Identifier. To do this you simply edit each with the proper names. For instance, I used IconLite.png for my icon file and used com.domain.mygamelite for the bundle identifier.

The bundle ID’s for the Lite and Full version of your game must be different in order for Apple to recognize that they are 2 separate applications and so that you don’t run into any issues when using the uploader.

That’s pretty much it for setting up the environment. It seems like a lengthy task, but once you’ve done it a few times, it should only take you about 5 min or so to get your environment setup for multiple apps within one project.

So lets go ahead and do some coding so I can show you how to use the environment we just setup to differentiate your code from being for your Lite version or for your Full version.

Within any file in your Xcode project, I am using a Cocos2D template so I will be using HelloWorldScene.m, all you have to do is place the following code:

#ifdef LITE_VER
//- Code that should be executed if the build target is set to MyGameLite
 
#else
//- Code that should be executed if the build target is set to MyGame
 
#endif

What the above code does is, it checks for compiler flags of LITE_VER, remember when we set the Other C and C++ Flags? Well this is where they get used. Anything between

#ifdef LITE_VER

and

#else

will get compiled if the Lite version build target is selected while everything between

#else

and

#endif

will not. You should be able to figure out how to move forward from here. I suggest that this be the first thing you do before starting the development of your game. The game I am currently working on is about 45% finished and it just now occurred to me that I need to start thinking about a Lite version. Even if you think that you will be making a free app, go ahead and make a Lite version anyways, you never know, and you might change your mind later.

Believe me, this is much easier to implement when you haven’t already spent months writing thousands of lines of code :(

So… I’m hoping that this was able to help someone, and if anyone needs any help or has any questions, feel free to leave me a comment.. Happy Developing