A trip from cocos2d-iphone to cocos2d-html5

With the help of the 3-day-break during Tomb-sweeping Day I finally finished this trip and reached the destination.

Frankly speaking I was only planning to write a short post about this trip at the beginning but when I get started I found there are way too much that I want to write down the I planned.

Then I happened to come across a wonderful tutorial from Ray wenderlich introducing how to create a book usign iBooks author and asked myself — why not? — and then this book was here πŸ™‚
Continue reading

[Part.2] A solution to “Using URLSchemes to send game level through e-mail”

3.Sending a e-mail inside your app

Before we start to use the URLSchemes we’ll need to add the “in-game-send-email” feature in our project.
That’s also easy to implement using the MFMailComposeViewController, you can check the demo project I wrote before:


For this tutorial, we’ll focus on the email-body part since we want embed the json content into a hyberlink such as “lauch my game level” like this:

NSString *emailBody = [NSString stringWithFormat:@”Launch Demo!!!“, jsonString];

Now we know how to send the email inside our app, let’s begin with the URLSchemes stuff.

4.Playing with the URLSchemes feature (sending and receiving)

For how to setting up the URLSchemes for your project, here is a great tutorial you can follow:


and for our project we’ll use the “URLSchemesDemo://” to launch our demo.

And before we sending and receiving the data with URLSchemes we’ll need to encode/decode the json content, we can do it like this:

[cc lang=”objc”]
– (NSString *)encodeToPercentEscapeString: (NSString *) input
// Encode all the reserved characters, per RFC 3986
// ()
NSString *outputStr = (NSString *)
return outputStr;

– (NSString *)decodeFromPercentEscapeString: (NSString *) input
NSMutableString *outputStr = [NSMutableString stringWithString:input];
[outputStr replaceOccurrencesOfString:@”+”
withString:@” “
range:NSMakeRange(0, [outputStr length])];

return [outputStr stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

4.1 sending the game level with URLSchemes:

In order to send the “game level” we need to embed our “game level” info (json) into the URLSchemes so that when your launch the project by clicking our URLSchemes the “game level” info will be sent to our project:

[cc lang=”objc”]
jsonString = [[GameDataManager sharedGameDataManager] encodeToPercentEscapeString:jsonString];
NSString *emailBody = [NSString stringWithFormat:@”Launch Demo!!!“, jsonString];

4.2 receiving the game level with URLSchemes:

To receive the data sent with URLSchemes is quite simple:

[cc lang=”objc”]
– (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
if (!url) {
return NO;

[[GameDataManager sharedGameDataManager] processReceivedGameLevel:[url absoluteString]];

return YES;

Then the “processReceivedGameLevel” function will decode the content and then save the level locally.

5.The summary

By now, we have finished our demo project with the following features:

1.generate a “game level” and save it to a json file locally
2.send the “game level” through email
3.launch the project with URLSchemes feature
4.receive the data attached inside the email and parse it into our json file(game level)
5.load the sent/received “game level”

Something to mention:

1.For a real app, you can make a “game level editor” for the user instead of generating the “game level” automatically like we do in the demo project

2.For the length of the data length limit of the URLSchemes, I haven’t found an actual number yet but I have tried with data with length over 10,0000 so I think that should be enough for most of the occasion πŸ™‚

Demo ScreenShot:

To Download Page…


If you feel all the stuffs in this site helped you a lot and you would buy me a beer πŸ™‚

Or get a game I made πŸ™‚


[Part.1] A solution to “Using URLSchemes to send game level through e-mail”

It is always a cool feature allowing your user to design a “game level” and then send it to his/her friends to show it off πŸ™‚

If you have a personal server then this might be easy to implement, you can also use the “challenge feature” in open-feint and in game-center maybe(I haven’t tried this though).

But all these solutions above requires you to have a game server or the user to have a open-feint/game-center account support.

A very simple solution here is to use the URLSchemes to implement this cool feature.

This tutorial will show you how to get these stuffs done:

1.Setting up the scenes
2.Playing with Json files (saving and loading)
3.Sending a e-mail inside your app
4.Playing with the URLSchemes feature (sending and receiving)
5.The summary

Continue reading