Preload images from URLs on the fly

Preload images from URLs on the fly
0.0 0



I’m new to cocos2d-html5.
Could someone kindly tell me how I can preload images from URLs (different domain) when the game loads.



Hi, @maxii

To preload a list of resource for one scene, you can use cc.LoaderScene:

], function () {
    cc.director.runScene(new MyScene());
}, this);

This method can ensure that your scene get started after all the resources have been loaded
If you want to load a list of resource at any other moment, you can use

], function(err){
    if(err) return console.log("load failed");

Full documentation of cc.loader



Thanks Huabin!
It seems that the cc.loader.load is from v3.0a. I’ll give it a try then!


Hi @maxii,

The feature loading URL from different domain has been supported.

{type:"serverImg", src:""}

More details please see:


Thanks Dingping!

I used the HelloHTML5World template to try this out.
when I put
{type:“serverImg”, src:“”},
into the g_resoutces
I got this exception:
uncaught exception: cocos2d:unknown filename extension: com/u/232330

I can create the sprite without preload it though, by directly write
this.sprite = cc.Sprite.create(“”);
in the myApp.js, it shows the image as expected.But, when I replacing the ""
with something like
the image don’t show up.

Also, when I try to add
{type:“serverImg”, src:“”}
to “resource.js”, the game stopped at “loading… 75%”


Hi @maxii,

Please let the server allow cross-origin.

About the error “uncaught exception: cocos2d:unknown filename extension: com/u/232330”.
Please update the latest of “develop 3.0” branch of Cocos2d-html5 from



Great! Thanks!


I really like this framework! My game runs smoothly!
Have another question:
My game will live on a page witch also has many other contents on it. When on mobile device, within the game area, I can’t swipe my finger to scroll the page to see the contents down below the game. Please advice how can I enable the scroll.

Any help would be greatly appreciated!!



Any suggestions?


OK, I understand that the game better runs on full screen mode, and I’m convincing my company to make the game page only contain the game itself.
But in the mean time, I’m still want give it a last try.
My game is actually pretty simple, all user have to do are just clicks, here is a demo:
I know this might sound dumb (I’m a newbie of html5): can I disable all the touches and only handle the mouse clicks for this game on a mobile device?
Again, I really like the cocos2d framework, and I really want make this work!
Please help!!




What do you mean by disable all the touches and handle the mouse clicks on a mobile device? since there are no mouse event on a mobile device.


Like the way you interacting with the usual html elements on the page: links, buttons, etc?
I don’t know if this even possible, probably not…


May be you can handle only one touch all the time, assume that’s the mouse ?


Thank you, I’ll try.