views:

355

answers:

8

I am interested in writing games for the iPhone and the Web. Ideally, there would be one language that I could write my games in and it would work on both platforms. I know this is not the case, so what is the best way to leverage code between iPhone apps (Objective-C/C++) and Flash SWFs (ActionScript)?

A: 

Actually, the iPhone supports Flash technically (see Developer creates Flash for iPhone and Flash Installer Update #2). It is just Apple's crippleware restrictions that prevent installation.

Other than that, there's really not much you can do. Flash/ActionScript and Objective-C are radically different. You can have a central server store data, but that doesn't solve the duplicated logic.

Matthew Flaschen
A: 

If you're already willing to use ActionScript you could go all the way over to the dark side and switch to Javascript. That's the only common language supported by your clients (web and iPhone).

Nikolai Ruhe
That doesn't really help him. First of all ActionScript does not even pretend to comply with the EMCAScript standard. Second, he is undoubtedly using Adobe APIs that have no JavaScript equivalent.
Matthew Flaschen
Branden Hall
+4  A: 

Unfortunately, Flash and Objective-C are very, very different - and it's unlikely that a Flash player will be available for the iPhone in the near future. The native input methods used in Flash games - the keyboard and mouse - don't lend themselves well to the iPhone. While Apple could make Flash run on the iPhone, most Flash games would be totally unplayable (or feel very unnatural. They'd have to overlay a keyboard probably?). With the success of the App Store and native iPhone games, I think it's very unlikely you'll see Flash support anytime soon.

You might want to consider using a game development tool like Unity instead of Flash in the future. Unity allows you to create both 2D and 3D games, and you can program them in various .NET scripting languages. Once you've created the game, you can cross-compile it for web (their own plugin, not Flash), iPhone, or the desktop.

I know that doesn't help much since you have an existing codebase, but it might be something to consider for the future!

Ben Gotow
Unity looks awesome, but I do hate that they have their own plugin instead of compiling to Flash. Browser penetration is key for web games that depend on ad revenue, and that is where Flash shines.
Andrew Garrison
+ for unity3d - rockin' good!
Iain
+7  A: 

This maybe of some help

It uses the NME library which will allows code to mostly be written to the Flash 9 API and create the C++ for XCode to compile and run on the iPhone and Touch. This creates a path to port Flash games to iPhone/Touch.

Ben Reeves
I hear that this is coming. I can't wait to try it. There have been some sample apps from Flash ported to the iPhone, but the performance is not that great. There are little delays in registering finger events and the animation is not that smooth...
milesmeow
A: 

How comfortable you are with either development environment certainly plays a role here. If you are a die-hard Objective C and a super star Actionscript programmer then doing both shouldn't be much of a problem. It will be lots of work of course, but not a problem.

However, if you are neither or only skilled at Actionscript then I suggest you focus on Flash/Actionscript for the time being. Eventually Flash will be available on the iPhone anyway. When that happens you can already have a number of apps ready to be quickly ported to iPhone. Also keep in mind. There are more portable devices out there than just iPhone. Getting your apps running on other devices might be worth it in the mean time.

Just keep in mind when you're developing your apps now that at one point you also want to run these apps on the iPhone. So make 'm in such a way that they can be controlled with an iPhone as well.

Luke
+1  A: 

Adobe Alchemy looks promising. It is not released yet, but from their website:

Alchemy is a research project that allows users to compile C and C++ code that is targeted to run on the open source ActionScript Virtual Machine (AVM2).

This would allow iPhone apps and Web apps to share non OS-dependent C/C++ code, which is a very exciting prospect.

Andrew Garrison
I've been hearing about that for awhile. Any word on how it's progressing?
Nosredna
Oh that link you posted is about how haxe copmpiles to C now (in latest beta, I don't think it's released). Haxe also compiles to JS, AS, Neco, and PHP. Haxe is very JS/AS-like.
Nosredna
Nosredna - I'm assuming that comment about Haxe is about Ben Reeves' answer.
Andrew Garrison
I must have clicked on the wrong link. Sorry. I was looking at this... http://drawlogic.com/2009/06/19/haxe-on-the-iphone-with-hxcpp-flash-9-api-to-c-for-mobile/ Which lets you compile Haxe to C and put it on the iPhone. Sorry. Don't remember how I did that.
Nosredna
+1  A: 

One option would be building everything in unity. The engine facilitates building the same game project to any of the following platforms:

  • Webplayer
  • OS X
  • Windows
  • iPhone
  • Wii
AngryAnt
Thanks for the suggestion, Unity does look awesome. Ben Gotow mentioned it a while back as an answer to this question.
Andrew Garrison
+3  A: 

Hi My company is developing a toolchain that allows compiling ActionScript3 to native code for mobile devices. It now supports Windows Mobile and Symbian, and iPhone supported will be released in a couple of weeks. Check it out at: http://developer.openplug.com/

BR

Guilhem

Guilhem
shameless plug, but it looks like an interesting product....upvote!
Andrew Garrison
Shameless "plug" :)
Ates Goral