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?
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:
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} ]
use cc.LoaderScene preload the resources list in main.js:
//load resources cc.LoaderScene.preload(g_resources, function () { director.replaceScene(new this.startScene()); }, this);