I am trying to load a game inside another webpage. The game get loaded to a different index.html file.
Because of this the game is not loading correctly.
When I checked I found that,
cc.assetManager.loadBundle
in “main.js” is trying to load files from wrong location.
Is there a way to set root location or a path of asset manager?
or
Is there a way to configure root location for the game ?
@SantyWang thank you for your answer.
Based on your answer I tried following modification;
At this time I have relative paths to the bundles.
I have modified following lines in main.js to set the paths.
var RESOURCES = window.gamePath + "assets/resources";
var INTERNAL = window.gamePath + "assets/internal";
var MAIN = window.gamePath + "assets/main";
I know the path is correct because I use the same path to load scripts here…
loadScript(window.gamePath + (debug ? 'cocos2d-js.js' : 'cocos2d-js-min.js'), function () {`
When I the new game I am still getting errors like;
GET http://localhost:8888/seven/assets/internal/config.json 404 (Not Found)
GET http://localhost:8888/seven/assets/internal/index.js
GET http://localhost:8888/seven/assets/resources/config.json
...
I am puzzle by the following script in main.js. It is loading scripts and I haven’t modified it.
Is this the cause of this error?
GET http://localhost:8888/seven/assets/internal/config.json 404 (Not Found)
GET http://localhost:8888/seven/assets/internal/index.js
GET http://localhost:8888/seven/assets/resources/config.json
But “cocos2d-js.js” file does get loaded correctly with following.
loadScript(window.gamePath + (debug ? 'cocos2d-js.js' : 'cocos2d-js-min.js'), function () {
This works. So window.gamePath is correct.
But for some reason when it comes to c.assetManager.loadBundle the path is failing!
Then I tried following
var RESOURCES = window.gamePath + "ZZassets/resources";
var INTERNAL = window.gamePath + "ZZassets/internal";
var MAIN = window.gamePath + "ZZassets/main";
“ZZassets” is clearly invalid path.
But still the loader is trying to load assets from, previous location and I get the same error;
GET http://localhost:8888/seven/assets/internal/config.json 404 (Not Found)
GET http://localhost:8888/seven/assets/internal/index.js
GET http://localhost:8888/seven/assets/resources/config.json
...
I expected to get something like
GET http://localhost:8888/seven/ZZassets/internal/config.json 404 (Not Found)
But I do not. Seems like there is another place the loader is picking up this path.
using window.gamePath “cocos2d-js.js” getting loaded correctly. Problem is with the resources.
I think “seven” is the folder where index.html file of the page that load the game is located. As I explained before I am trying to integrate my game to run in external game server.
This page get integrated into server’s index.html page.
Files inside “seven/game/web-mobile” get integrated to the web page.
I have successfully get the game loaded on this server with the previous version of Cocos Creator. With the introduction of cc.assetManager.loadBundle this is failing.
window.gamePath is relative folder path. For example
…/…/Games/seven/blackjack/web-mobile/
This path is correct. And with this path I was able to load the script “cocos2d-js.js”
But it does not seems to work with cc.assetManager.loadBundle
Even if this path was incorrect, based on the test I have done before (change folder to ZZassets) it should print the invalid path in the error message.
I am not 100% sure this simulate the exact conditions since we are running our game in external company game server.
But this also have similar problem.
“ResourceTest_example_game_files” folder has the application I build
“ResourceServer” folder I have created a very simple web server and copied the build folder in there.
the node server can be found here;
Or you can use any other server.
What I have done is;
In the root folder of the web server I have index.html file with an iFrame in it.
I am loading the game into the iFrame with the path;