[Resolved][PhoneGap] Unable to load TMX and JSON files


Hey guys, me again! :smiley:

My last work into Cocos2d-html5 drive me to try a lot of new things, including JSB and running in multiple browsers the same game, and I can say that I am pretty impressed with the compatibility of the lib, nevertheless I still need some help.

I realize that the performance of the Mobile IE10 is pretty good, mainly testing it in the Windows Phone 8. Given that fact I am trying to run my game thru PhoneGap.

I got it working with a pretty good success and not that much trouble, yet I hit two main problems:
When loading the resources of my game it stops at 94% at what I believe is the TMX loader and another JSON resource that I have added to be loaded as a XML (works in the Mobile browser and in JSB).

Removing both files the game runs pretty well, of course it is a big problem since we cannot load our game scene that uses the TMX Tiled Map.

I have set the files to load as Content into the Visual Studio and I have loaded the function of the cocos2d.js just after the onDeviceReady() function of PhoneGap.

Will be trying to fix that, but if anyone has encounter similar problem would be nice to save some time :P.



Ok, I found the problem and I worked a workaround to get a fast solution.

The main problem was that the filesa are into the folder www/ (that are the root for files in PhoneGap), but when referring to them into my code I just used /res, and not the www at the front.

With images and the other files everything went good, but with XML files there’s a problem, since it uses the XMLHttpRequest that is handle by the file cordova-2.7.0.js (or your version of PhoneGap). You can fast solve this for json files just adding the “www/” into the address of the files into your resource.js, but for TMX files you will get an error when trying to load the images related to that TMX.

My workaround was to add a handle into the method that handles the XMLHttpRequest of Cordova that is into the “cordova-2.7.0.js” file, so I use the Find into that script with the string “app/www/” and added a new if into the session of the code, it wold look like that:

// prefix relative urls to our physical root
if(newUrl.indexOf(“app/www/”) < 0 && this.getContentLocation() this.contentLocation.ISOLATED_STORAGE)
newUrl = “app/www/” + newUrl;
if (newUrl.lastIndexOf("/") = newUrl.length - 1) {
newUrl = “index.html”; // default page is index.html, when call is to a dir/
if == “res/”) {
newUrl = “www/”

And that’s done :wink:


Thank you for sharing that information with us.

Sorry for none experiences on PhoneGap, and blissful that it had been resolved at last.