[Resolved]question about addSpriteFrames

[Resolved]question about addSpriteFrames
0.0 0


the codes(all wrote in MyLayer.init) below show different results.

code 1:
cc.SpriteFrameCache.getInstance().addSpriteFrames("res/figures/fi1ms.plist"); this.addChild(cc.Sprite.createWithSpriteFrameName("fi1m.png"));
native:sprite is show.
html5:sprite is empty.

cc.SpriteFrameCache.getInstance().addSpriteFrames("res/figures/fi1ms.plist"); cc.SpriteFrameCache.getInstance().addSpriteFrames("res/figures/fi2ms.plist"); this.addChild(cc.Sprite.createWithSpriteFrameName("fi1m.png")); this.addChild(cc.Sprite.createWithSpriteFrameName("fi2m.png"));
native:two sprite are both show.
html5:sprite[fi1m.png] is show when the other one is not.

what can I do to make it works as the same as in native?


Do you preload resources before you use them?

Because the resource need send a HttpRequest to request it from Server, and it isn’t return immediately, so we need preload the resource before we use it.

for example in HelloHTML5World:

  1. define a preload resources list in resource.js:

var s_HelloWorld = "res/HelloWorld.png"; var s_CloseNormal = "res/CloseNormal.png"; var s_CloseSelected = "res/CloseSelected.png"; var g_resources = [ //image {src:s_HelloWorld}, {src:s_CloseNormal}, {src:s_CloseSelected} ]

  1. use cc.LoaderScene preload the resources list in main.js:

//load resources cc.LoaderScene.preload(g_resources, function () { director.replaceScene(new this.startScene()); }, this);


a ha! so it is!
I preloaded all the plist files, but not any png file.
thank you very much. good man one life safe~~