Cocos2d -> Cocos2dx rewrite Update 1 (4 Hours)

I am 4 hours into the conversion. I decided to just go scene by scene, so I began by loading in my splash screen and loading scene. The loading scene is something I wrote for cocos2d a while ago and use it in many apps, it’s available on github (although I do need to update that one as I’ve made a couple small enhancements). So I took that and ported it all to cocos2d-x. This was a great place to start because it has some file reading / parsing code in there.

I haven’t done this before on cocos2d-x, and I must say they’ve done a great job. I am able to use all my existing dictionaries (plist) files and parse them just as I did previously, so it was just a matter of updating the syntax to C++ from OBJC and away I went. So in my loading class I do a few things, first I cache all my sprite sheets, sounds, images, etc, then for this game I generate the dictionary which will be used for the game. This is some custom code I have, so it needed to be converted as well. Thankfully most of the code was in C++ already, as that’s usually how I write my performance code. So it was simply going from NSArrays to CCArrays, and changing a few types here and there.

All in all, after 4 hours, I did the whole loading screen, splash screen, and 90% of the core engine. So by going this path, I’ve actually tackled the more technical bits first, as displaying things on the screen is much easier code to migrate. So I think at 8% done I’m making great time.

Next Post:

Rewrite a cocos2d application in cocos2dx in 48 hours

We have an app that is on the iOS store and still waiting review for Mac store. Word Jumblerama Blitz. It’s a quick word game that was a lot of fun to make, and people seem to enjoy playing it. We made the initial release in a week, and now are thinking of porting it to a wider platform to support more devices.

Originally it was written in Objective-C using cocos2d (v2.0). We will now rewrite and migrate the app to c++ using cocos2dx (v2.0). We have done cocos2dx work before, and migrated a smaller app. There are a lot of nuances with this app, such as file reading, writing, parsing huge dictionaries on the fly, etc. So it’s a learning exercise as well as an excuse to do a little android work (which is truly punishing, it’s really not our favorite platform by miles), but cocos2dx does help a lot. Along the way we’ll probably do some JNI to talk to java, but at the same time we don’t just want to do an android port. I want the whole app to be on cocos2d-x, so the next version for Apple will be on the cocos2d-x (C++) code.

The goal is to truly have a cross development / cross platform solution. I always dev iPhone/iPad/Mac on the same code, this time we’ll push it to more platforms including Android, and Windows. Our target is a complete app feature set to our latest release, (minus the iOS specific game center, iAd, etc) running on cocos2dx. Initially we’ll just aim for a iOS version in this first pass of the code, then use that to migrate to other platforms.

And we’ll time cap this at 48 hours (however, it may be broken apart in multiple days, depending on other work).

First Update (4 Hours)

Using AFNetworking with PHP to post to your own webserver (Example included)

Hello all,

I thought I’d start adding some bits of knowledge on here to help fellow developers. Every now and then I hit a hurdle that takes longer than expected to jump over, today it was with AFNetworking, an amazing little class for iOS/Mac development for doing network communications. I just have been a bit rusty on my php (7 years since last used), so it took me a little head banging to figure this out. It was extremely simple, but I had to go through a few herrings to get there.

I wanted a way for my beta testers to send me reports via the application, including autogenerated debug data.

#1) Have testers take screen shots and upload them. (Not user friendly, and lots of extra work for me to recreate the scenarios).
#2) Use a NSData of all the information I needed and upload it to my webserver. (ideal, just haven’t done that yet)

A little digging pointed me to AFNetworking, .

This looked great. Very easy to integrate, and seemingly easy to get up and running. But a couple caveats. Now like I said my php knowledge is long retired, I love the language, I just haven’t used it in years. So this would take a little head scratching. But the basics of what we’re doing is this.

#1 Install AFNetworking in your project (follow instructions from code, very simple, copy files, #include header, done).
#2 Create NSData to send (in this example a simple image)
#3 Package the data up in a JSON request with AFNetworking
#4 Send the request to webserver which has a php file to process the request. (in this case, take the file and copy it to a directory).

Ok, well #1 was easy we already do this in other parts of our code. But here’s the snippet for using an image bundled with your project. Oh and since we’re using UIImage, you need to import UIKit framework to your project if you haven’t already. UIImage is for iOS only, mac uses NSImage, but it’s very similar.

//This will look for a file called Default.png in your bundle
NSString *imgPath = [[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"];
//This loads the image into a NSData variable we'll use to send the message with
NSData *imgData = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:imgPath]);

NSString *imgFileName = @"myDynamicFile.png";

Great. So we have that done. Now we construct the package from AFNetworking.

AFHTTPClient *client= [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:@""]];;
NSMutableURLRequest *myRequest = [client multipartFormRequestWithMethod:@"POST" path:@"upload.php" 
                                                             parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
   [formData appendPartWithFileData:imgData name:@"uploadedfile" fileName:imgFileName mimeType:@"images/png"];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:myRequest];
[operation setUploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
	NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite);
	[operation setCompletionBlock:^{
		NSLog(@"%@", operation.responseString); //Lets us know the result including failures
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];

Great! Now what I’ll point out is a bit I got stuck on.
This command:

   [formData appendPartWithFileData:imgData name:@"uploadedfile" fileName:imgFileName mimeType:@"images/png"];

The first argument is the NSData* we will pass, the next ‘name’ field is important. I was confused on the difference between this and filename, the last is the mimeType, make sure it’s appropriate for your file type, you can go here for valid types: .

So like I said I was confused on ‘name’ and ‘filename’, the filename is self explanitory, but the ‘name’ wasn’t, I later found in debugging that is going to be the name of the post object, so on our php script we’ll be iterating through that object (which comes as an associative array). So just hold that thought for now, we’ll show in the next step.

Now we need our PHP script setup on our server. A couple red herrings, make sure you have folder access and write access to your folders. Sometimes things like WordPress do a bunch of redirects which can cause your scripts to fail, we had this issue at one point, and had to modify .htaccess (I won’t cover that here, just googlie “wordpress exclude redirect”).

The script will be located in the path specified in the URL above, and it’ll be called ‘upload.php’ in this example. After a post is received, the script simply copies that to a subfolder called ‘uploads’ in this example.

Contents of upload.php

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";

Ok remember that bit I got stuck on? That was the ‘uploadedfile’ which was the name we were passing from the JSON request. Initially I had a mismatch which would cause the php to not see any file as it was looking inside of $_Files[‘uploadedfile’], when in fact I sent something like $_Files[‘attachment’]. The truth is you can have it named anything, just make sure they match! a small doh moment, but once I remembered how to debug a little php I sorted it out.

This is very simple… but hopefully it helps someone, if anything it’ll help me when I have to revisit this code. I wouldn’t use this code as-is, there is no type checking at all on the php, you may want that to validate your data and not crash your server (large files, etc).

I have to get back to work now to implement this in our new apps, highly likely there’s a typo in the code so feel free to correct it.

Welcome to the New Year – 2012

Well the New Year is here. This year we plan on working hard to build up our brand and get more product out the door. We have some exciting projects in progress, we’re looking forward to working with some 3rd parties, and of course we will be updating our existing applications with new features.

A wrap up of last year:

March – Mojo Video Poker for Mac, the app has remained in the top 10 in Casino games on OSX since it’s release.
October – Mojo Video Poker HD for iPad.
December – Retro Art Studio for iPad.

We continuously updated our products throughout the year adding functionality and fixing issues. We released a total of 10 updates across all our apps.

We prototyped in house and for 3rd parties over 30 games and apps in 2011. Some of these ideas will be realized in 2012 as new releases, either by us or by a 3rd party publishing company. We have a lot of exciting projects lying around, and now we have to filter some out to release in 2012.

Our outlook:
We have a lot of sticks in the fire this year, and now we’re looking to move some projects ahead. We hope to pick up some new contacts and partnerships along the way. This is what we currently have planned.

  1. Mojo Video Poker (OSX/iPAD) update, this will bring new features to both applications, including auto-hold for all games. This is currently in testing.
  2. WJ – (iOS/OSX) This is a new application that has been in development for 9 months. We are getting close to the polishing stage. We are very excited for this release and hope we can get it to the finish line before end of Q1.
  3. Retro Art Studio (All) this is an update to Retro Art Studio our free to play retro art game collection. We are expanding our platforms and looking at touching new platforms we haven’t yet delivered to. This is hopefully in line for release in Feb / March. We also plan on a latter release adding new themes and art programs to the mix
  4. BS – (iOS/OSX) This is a new puzzle game we are currently developing. We hope to find the time to build up some levels to make it interesting and get it to users this year.
  5. Episode 9 – (iOS) This is a very large title we hope to do this year. This is bringing to life a popular series of cartoons we published years ago. We plan to make an interactive game / story that will take players through the adventures of our fearless hero.
  6. Finance Apps – (iOS/TBD) A collection of apps to manage different aspects of finances. A collection of tools we’ve had internally we’ve found useful over the years.

If we have time projects, these are ones we’ve started and would love to work more on.

  1. GORB – (iOS) The gravity based action puzzle
  2. The Adventurers – (iOS) A retro-ish point and click adventure
  3. TnP – (iOS/Other) A collection of musical toys for children
  4. Color With Me – (iOS/Other) A coloring program for children
  5. Money Match Extreme – (All) A revisit to our original mobile title, Money Match Advance. An fast action thinking puzzler. This is a labour of love an hope one day to bring it back.
  6. Many Many more…

That doesn’t touch on our 3rd party partnerships… All in all it’s going to be a busy year! We can’t promise it all, but we hope we’ll be bringing everyone some great apps this year.

R.I.P. Steve Jobs

Here’s just a small note about a great man.

I worked at Apple for 5 years from 2003-2008, my first year there I was a contractor. When you start at Apple you would hear the ‘elevator’ horror stories of Mr Jobs. No one knows if they’re true or not, but it made him a legend and people got out of his way.

Well, within my first month at the company I was walking down from the 3rd story of the building I worked in. I then heard some footsteps behind me, so I began to pick up the pace of my steps. The person following picked up their pace, and eventually I felt like I was running down the stairs, I finally got to the huge metal security door and pushed my way through. I then had to see who was following me, so I turned and lo and behold, it was Steve Jobs. He was carrying a cup of coffee and on his way out the door. I then turned and reached out to hold the heavy steel door to let him through… and for some reason, I just let the door close, right on him. The coffee splashed all over, and as quick as I could I ran out of the building.

Well I ended up having a long career there, and that was the one of the two run ins I had with Mr. Jobs. That’s the only good anecdote I have of the late great Mr. Jobs. He was a good man, and did amazing things regardless of the platforms we use.

Mojo Video poker gets big(ger)

Not only is Mojo Video Poker the best bang for your buck in iPhone Video Poker. It features 3 unique game types, 6 game modes, for a total of 18 games. Full gamecenter integration with achievements and leaderboards, and now, it’s getting Bigger.

We at Six Foot Three Foot are always happy to hear from our users, whether it be a bug, a request, or a quick ‘hello’. Well we have heard the most requested feature is to have larger cards, as we have maxed out the space on the screen as far as cards, we are working very hard on a whole new way to play Mojo Video Poker. We are in the middle of supporting Landscape mode, the future version will allow you to play the game how you have been, or you can tilt the iphone / ipod to it’s side and play it in a wide screen mode which brings a new layout and larger cards to the screen.

We have been actively working hard on this using our own custom programming code to allow both methods of play to be fully supported without interrupting game play. We are still “work in progress” but feel free to have a look to get an idea of what we’re doing. (Also you can see the new cards we put in.)

Thanks for playing, and please rate us if you enjoy playing!