I created a plugin for Ejecta (impactjs.com/ejecta/overview) and successfully exported Space Blaster to an XCode project that runs it on Ejecta. I had to do some tweaks to the generated c2runtime.js file but the game works well. Actually, most of it, because ejecta does not support tiled backgrounds, so the health bar does not draw very well. The YouTube video of space blaster running on Ejecta in my iPad with GameCenter is here:
youtube.com/watch
The steps I did are the following:
1. exported as Html5 game
2. Modified runtime.js in the following places
a. set this.isDomFree = true and this.isiOS = true in function Runtime(canvas)
b. set this.ctx = global_ctx; in function Runtime(canvas). global_ctx is just an arbitrary global var that holds the 2d context obtained in the index.js script (see Ejecta documentation). That was the only way I could make it work, not sure why.
c. In areAllTexturesLoaded, I replaced the end of the function with the following:
this.progress++;
return (this.progress > 250);//got 250 through trial and error
and replaced the following line in Runtime.prototype.go:
this.progress = 0;
with:
this.progress = (typeof this.progress === 'undefined') ? 0 : this.progress ; //jpt
to allow the progress variable to keep track of my arbitrary progress (maximum is 250).
This is caused by Ejecta not supporting the filesize info that C2 polls in areAllTexturesLoaded. A fix is needed for this, I will try to find a way of just using chained ?onloadimages? to detet if all images are loaded, or something like that. Smarter suggestions are very welcome.
3. Created a index.js file for ejecta with the following contents:
var global_canvas = document.getElementById('canvas');
var global_ctx = canvas.getContext('2d');
ejecta.require('c2runtime.js');
// Create new runtime using the c2canvas
cr.createRuntime('canvas');
I marked my changes to c2runtime with "//jpt" so you can see in the source what I changed. The Xcode source, with the capx and the Ejecta plugin are in:
dropbox.com/sh/wp9wzw1yxd6pz9a/NODC9JCZMr
The Ejecta plugin so far only has the actions and conditions to authenticate into GameCenter and to post scores and achievements.See impactjs.com/ejecta/game-center for info on what Ejecta supports in GameCenter.
Please understand that you will not be able to just run the Xcode project in your Mac. You will have to:
1. Get an Apple dev account
2. Create all your certificates and app IDs (this is not C2 specific, you have to do that with any IOS app you want to develop in any tool)
3. Setup GameCenter for your app ID. See cocos2d-iphone.org/forum/topic/20998 (ignore the cocos part and just follow the iTunes Connect tuturial)
4. change the bundle identifier of the Xcode project to your own bundle identifier.
5. GameCenter will work 24 hurs after you set it up.
6. Scores will not show until more than one GameCenter Account pots a score. I ahd to create an extra account and play SpaceBlaster with it to make the scores visible.
Disadvantages of using Ejecta:
1. Tiled backgrounds don?t work properly
2. No file size support, need to find fix. For now I just have the loader wait an arbritary number of seconds.
3. Not all HTML5 is supported. I know for sure XMLParser does not work (tried to use the TMX imported from RexRainbow in another experiment). Please see impactjs.com/ejecta/supported-apis-methods to see what part of HTML5 ejecta supports.
4. You have to know XCode. Make sure you try follwoing a tutorial on the web on how to do a Native Hello World IOS app in Xcode so that you can learn how to work with certificates and app IDs.
5. You have to have a Mac; but you need one anyways to publish to the app store. I got my 2009 macbook for about $250 at cedarpc.com plus 4GB at $35 from crucial. The screen has some white spots but they are no big deal.
6. You need to understand JavaScript in order to make the chnages to the c2runtime.js file. Please don?t try this experiment unless you know some javascript programming and are comfortable with XCode.
Advantages of using Ejecta:
1. Current GameCenter support. I know CocoonJS has now an API for that but I think it involves contacting them or something like that.
2. Is open source so it is free. No monthly fees or sharing revenue.
3. It has ways to allow your JS to communicate with Objectitve C code if you need to implement something natively (http://impactjs.com/ejecta/extending-ejecta)
4. Performance wise, I will say it is good. But CocoonJS is also fast, so there is not much difference. In my iPhone 5 it ran really well, in my iPad2 it ran smooth but it did drop sometimes to ~35 fps at some points in the game.
5. Their GitHub page says they are working on implementing WebGL (https://github.com/phoboslab/Ejecta)