Tom Ortega II

My first iPhone app – A Flex app port naturally! :)

In Uncategorized on August 5, 2009 at 2:54 pm

Fair readers of this blog may recall my Tic-Tac-Toe posts from awhile back.  The gist of the posts was this: I wanted to learn game dev, so I built a Tic-Tac-Toe game in Flex.  The plan was to start with really poorly written mxml files and then gradually improve them to more advanced AS3 files.  You can play the finished game here.  Now it was a lot of hardcoded logic, poor design, etc, but the point was to get something working pronto.

I pulled that game up the other day because my son and I like to play Tic-Tac-Toe on paper.  After a few minutes of playing online, my 5-year old threw down the gauntlet, “Dad, can I play this on the iPod [touch]?”  Never to be one to step away from a challenge, I said, “Not this one.  I’ll have to make a new one just for the iPod.”  To which he replied, “Okay, let me know when it’s done.”

That’s the thing about kids.  They don’t know, nor do they care, about how hard something is.  They just want to know when the final product is done, whether that be a baby brother or an iPod Touch game.

I’m about halfway thru Dave and Jeff’s iPhone Dev book after finishing Mark’s Objective-C book.  Therefore, I was jonesing for my own project as it was, so my son’s request just gave me the excuse to give it a go.

Well, it took ’til Monday night, but behold!

Tic-Tac-Toe

As you can see, I’ve got a working version of the app.  Since I knew I wouldn’t be submitting this to the app store, I spruced up the gameboard a bit.  My son is just starting to read, so he can recognize keywords like his name, “love” and “dad”.

The code was almost a literal port, i.e. the hideous flex code was matched by equally hideous Objective-C code.  What’s interesting is that with my flex code, I kept it basic except for the use of States.  In my Objective-C code, I kept it basic except for the use of Categories (instead of sub-classing).

All in all, I’m happy with the project.  Here’s some quick questions and answers:

Was it tough porting the app from the Flex SDK to the iPhone SDK?

The start was a bit rough as I was trying to literally port with states and all.   The hardest part for me to grasp was separating my model into it’s own class.  I didn’t do that in the Flex version and so was trying to add game properties to my game’s ViewController in Objective-C.  That didn’t work out so hot to say the least. LOL

Is Objective-C programming really that different?  How does Xcode compare to Flex Flash Builder?

By the end, i was feeling my Objective-C mojo.  I saw where I could optimize things and did tweak a few files after I had a working version on my iPod Touch.  Objective-C is certainly a different beast.  Functional Testing *needs* to be done on the device.  It’s so much nicer and just *feels* right.

Xcode is a dream IDE to use though.  No offense meant to my Flash Builder homiez.  However, I’m sure Apple has a whole army dedicated to making Xcode, so it’s not a fair comparison.  Plus, I’ve barely touched the surface as far as Xcode’s features.

Is the iPhone version more complex than the Flex version?

Yeah, by default it is because Objective-C is a real low-level language versus ActionScript3 which mimics one.  You have memory allocation, etc.  Also, the way the SDK works, you must have an Model-View-Controller architecture from the get go.

However, I can really see the power of Categories and how that would solve a lot of inheritance issues in Flex.  As my son would say, I felt “tricky-tricky” for using such an advanced concept in my humble first little app.  It just made so much sense though, since my Flex version subclassed Button to create GamePiece.  I had to do something similiar to truly create a port. Therefore, I created a “GamePiece” category on top UIButton, which works great, especially since sub-classing UIButton is sort of a big no-no.

Am I done with Flex now and gonna turn traitor?

Heck, no.  Objective-C is nice and all, but I’m definitely not as versatile there as I am in Flex.  Plus, each platform has its own strengths and weaknesses.  I will continue delving deeper into the Objective-C waters though.  I haven’t done any low level programming in awhile, so it’s definitely refreshing to have that much power!  🙂

A Funny Side Story

Monday, I went back to my machine.  I noticed that my XIB for the iPhone game had regressed.  (You can think of a XIB file as the design view for your app except you don’t have access to the underlying code.)  I was thinking Xcode wigged out or something.  After fussing for a few minutes, I decided to just rebuild the XIB file (i.e. all the visuals you see in the screen shot above).

At some later point, my son walked up and saw me working on the app.  “Oh Dad, yesterday, I was playing Tic-Tac-Toe on your ‘puter.  I saw the new Tic-Tac-Toe game and I started to make the lines and pieces disappear!”  It wasn’t an Xcode project, but more of a “5 yr-old making magic” problem.  LOL

Advertisements
  1. great post. Does the interface still look similar or can u tell it’s ported from flex? I have no idea when it comes to c. Reading apples site just baffles me so this might be my only option.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: