Thanks to vikerman, I was able to get Space Blaster running on webgl in ios using Ejecta (latest build from GitHub). It feels faster than the ejecta canvas version I did before. The TileBackground plugin now works perfectly. I was also able to use the radial blur effect when one of the enemies hit. Hopefully, it is clear in the video when the effect takes place. The youtube video is at
To make it work, I did a diff on Vikerman's work and was able to identify where in the c2runtime.js file you need to make changes for webgl to work on ios with ejecta (no need to do the changes shown in the 1st post of this thread, that is for canvas):
1. In GLWrap_.prototype.loadTexture remove the last parameter in hte function declaration, so that it reads:
function (img, tiling, linearsampling, pixelformat) //jpt
2. In GLWrap_.prototype.loadTexture after gl.texImage2D(gl.TEXTURE_2D, 0, internalformat, format, type, img);
the following if condition needs to be removed:
if (tiling)
{
?if (tiletype === "repeat-x")
?{
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
?}
?else if (tiletype === "repeat-y")
?{
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
?}
?else
?{
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
?}
}
else
{
?gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
?gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
}
and replaced with:
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, tiling ? gl.REPEAT : gl.CLAMP_TO_EDGE); //jpt tiling restructured
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, tiling ? gl.REPEAT : gl.CLAMP_TO_EDGE);//jpt tiling restructured, replaces the if(tiling) part
4. In function Runtime(canvas) add
this.isEjecta = !!window["ejecta"]; //jpt
after this line
this.isCocoonJs = !!window["c2cocoonjs"];
5. Replace
this.isDomFree = this.isDirectCanvas || this.isCocoonJs;
with
this.isDomFree = this.isDirectCanvas || this.isCocoonJs || this.isEjecta; //jpt
6. also in same function, replace the following:
if (typeof jQuery !== "undefined" && this.fullscreen_mode > 0)
?this["setSize"](jQuery(window).width(), jQuery(window).height());
?
with
if (typeof jQuery !== "undefined" && this.fullscreen_mode > 0 && !this.isEjecta)
?this["setSize"](jQuery(window).width(), jQuery(window).height());
?
7. In the next "if", replace it with:
if (this.enableWebGL && (!this.isDomFree || this.isEjecta)) //jpt
8. Surround the following code with an if for ejecta:
?jQuery(this.overlay_canvas).appendTo(this.canvas.parentNode);
?this.overlay_canvas.oncontextmenu = function (e) { return false; };
?this.overlay_canvas.onselectstart = function (e) { return false; };
?this.overlay_canvas.width = canvas.width;
?this.overlay_canvas.height = canvas.height;
?this.positionOverlayCanvas();
?
so it should read:
?if (!this.isEjecta)
?{
?jQuery(this.overlay_canvas).appendTo(this.canvas.parentNode);
?this.overlay_canvas.oncontextmenu = function (e) { return false; };
?this.overlay_canvas.onselectstart = function (e) { return false; };
?this.overlay_canvas.width = canvas.width;
?this.overlay_canvas.height = canvas.height;
?this.positionOverlayCanvas();
?}
9. Add the check in Runtime.prototype.go:
replace:
if (this.overlay_canvas)
with:
if (!this.isEjecta && this.overlay_canvas) //jpt
10. In Runtime.prototype.go_textures_done:
add a check around this.canvas.parentNode.removeChild(this.overlay_canvas) :
?if (!this.isEjecta)//jpt
?{
this.canvas.parentNode.removeChild(this.overlay_canvas);
?}
11. also, in the same function, add check to
if (this.fullscreen_mode >= 2) :
So it should read:
if (!this.isEjecta && this.fullscreen_mode >= 2)
The XCode project for the Space Blasters using WebGL with the modified c2runtime.js file is at http://sites.google.com/site/jptarqu/downloads/SpaceBlastersWebGL-ejecta-xcode.zip?attredirects=0&d=1
By the way, I only wanted to test WebGL in this space blaster version so I left out the GameCenter actions/events I did for my previous experiment. The GameCenter should work even if you use webgl. Also, note that in order to keep good performance on your mobile game, you need to still follow the general guidelines for mobile that have been floating around in this forum, i.e.: not drawing more than 3 times into a pixel, keep physics object count low, use tiled backgrounds instead of sprites when possible, etc.