Navigation Menu

Skip to content

Commit

Permalink
fixed #1080 cc.Loader
Browse files Browse the repository at this point in the history
  • Loading branch information
ShengxiangChen committed Sep 18, 2012
1 parent 65eddfe commit 3445fb6
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 65 deletions.
8 changes: 4 additions & 4 deletions CocosDenshion/SimpleAudioEngine.js
Expand Up @@ -145,7 +145,7 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
this.removeEventListener('canplaythrough', arguments.callee, false);
}, false);
soundCache.addEventListener("error", function (e) {
cc.Loader.shareLoader().onResLoadingErr();
cc.Loader.getInstance().onResLoadingErr();
}, false);
soundCache.addEventListener("playing", function (e) {
cc.sharedEngine._isBgmPlaying = true;
Expand All @@ -159,7 +159,7 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{

this._bgmList[path] = soundCache
}
cc.Loader.shareLoader().onResLoaded();
cc.Loader.getInstance().onResLoaded();
},
/**
* Play background music.
Expand Down Expand Up @@ -513,7 +513,7 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
false);
}, false);
soundCache.addEventListener("error", function (e) {
cc.Loader.shareLoader().onResLoadingErr();
cc.Loader.getInstance().onResLoadingErr();
}, false);*/

// load it
Expand All @@ -522,7 +522,7 @@ cc.AudioEngine = cc.Class.extend(/** @lends cc.AudioEngine# */{
this._audioList[path] = [];
this._pushEffectCache(path);
}
cc.Loader.shareLoader().onResLoaded();
cc.Loader.getInstance().onResLoaded();
},

/**
Expand Down
8 changes: 4 additions & 4 deletions Demo/HelloDomMenu/main.js
Expand Up @@ -32,13 +32,13 @@ var cocos2dApp = cc.Application.extend({
cc.COCOS2D_DEBUG = this.config['COCOS2D_DEBUG'];
cc.setup(this.config['tag']);
cc.AudioEngine.getInstance().init("mp3,ogg");
cc.Loader.shareLoader().onloading = function () {
cc.LoaderScene.shareLoaderScene().draw();
cc.Loader.getInstance().onloading = function () {
cc.LoaderScene.getInstance().draw();
};
cc.Loader.shareLoader().onload = function () {
cc.Loader.getInstance().onload = function () {
cc.AppController.shareAppController().didFinishLaunchingWithOptions();
};
cc.Loader.shareLoader().preload([
cc.Loader.getInstance().preload([
{type:"image", src:"res/HelloWorld.png"},
{type:"image", src:"res/CloseNormal.png"},
{type:"image", src:"res/CloseSelected.png"}
Expand Down
8 changes: 4 additions & 4 deletions Demo/NativeClientDemo/main.js
Expand Up @@ -32,13 +32,13 @@ var cocos2dApp = cc.Application.extend({
cc.COCOS2D_DEBUG = this.config['COCOS2D_DEBUG'];
cc.setup(this.config['tag']);
cc.AudioEngine.getInstance().init("mp3,ogg");
cc.Loader.shareLoader().onloading = function () {
cc.LoaderScene.shareLoaderScene().draw();
cc.Loader.getInstance().onloading = function () {
cc.LoaderScene.getInstance().draw();
};
cc.Loader.shareLoader().onload = function () {
cc.Loader.getInstance().onload = function () {
cc.AppController.shareAppController().didFinishLaunchingWithOptions();
};
cc.Loader.shareLoader().preload([
cc.Loader.getInstance().preload([
{type:"image", src:"res/HelloWorld.png"},
{type:"image", src:"res/CloseNormal.png"},
{type:"image", src:"res/CloseSelected.png"}
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions HelloHTML5World/main.js
Expand Up @@ -32,13 +32,13 @@ var cocos2dApp = cc.Application.extend({
cc.COCOS2D_DEBUG = this.config['COCOS2D_DEBUG'];
cc.setup(this.config['tag']);
cc.AudioEngine.getInstance().init("mp3,ogg");
cc.Loader.shareLoader().onloading = function () {
cc.LoaderScene.shareLoaderScene().draw();
cc.Loader.getInstance().onloading = function () {
cc.LoaderScene.getInstance().draw();
};
cc.Loader.shareLoader().onload = function () {
cc.Loader.getInstance().onload = function () {
cc.AppController.shareAppController().didFinishLaunchingWithOptions();
};
cc.Loader.shareLoader().preload(g_ressources);
cc.Loader.getInstance().preload(g_ressources);
},
applicationDidFinishLaunching:function () {
// initialize director
Expand Down
57 changes: 28 additions & 29 deletions cocos2d/CCLoader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cocos2d/label_nodes/CCLabelBMFont.js
Expand Up @@ -154,7 +154,7 @@ cc.BMFontConfiguration = cc.Class.extend(/** @lends cc.BMFontConfiguration# */{
},

_parseConfigFile:function (controlFile) {
var data = cc.SAXParser.shareParser().getList(controlFile);
var data = cc.SAXParser.getInstance().getList(controlFile);
cc.Assert(data, "cc.BMFontConfiguration._parseConfigFile | Open file error.");

// parse spacing / padding
Expand Down
6 changes: 3 additions & 3 deletions cocos2d/platform/CCFileUtils.js
Expand Up @@ -99,7 +99,7 @@ cc.FileUtils = cc.Class.extend({
xhr.onload = function(e) {
var arrayStr = xhr.responseText;
if(arrayStr){
cc.Loader.shareLoader().onResLoaded();
cc.Loader.getInstance().onResLoaded();
selfPointer._fileDataCache[fileUrl] = selfPointer._stringConvertToArray(arrayStr);
}
};
Expand Down Expand Up @@ -214,7 +214,7 @@ cc.FileUtils = cc.Class.extend({
* @return {object} The Dictionary of object generated from the file
*/
dictionaryWithContentsOfFile:function (fileName) {
var parser = cc.SAXParser.shareParser();
var parser = cc.SAXParser.getInstance();
this.rootDict = parser.parse(fileName);
return this.rootDict;
},
Expand Down Expand Up @@ -283,7 +283,7 @@ cc.DictMaker = cc.Class.extend(/** @lends cc.DictMaker# */{
* @return {Array}
*/
dictionaryWithContentsOfFile:function (fileName) {
var parser = cc.SAXParser.shareParser();
var parser = cc.SAXParser.getInstance();
this.rootDict = parser.parse(fileName);
return this.rootDict;
}
Expand Down
25 changes: 18 additions & 7 deletions cocos2d/platform/CCSAXParser.js
Expand Up @@ -173,13 +173,22 @@ cc.SAXParser = cc.Class.extend(/** @lends cc.SAXParser# */{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp != null) {
var that = this;
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
cc.Loader.getInstance().onResLoaded();
that.xmlList[filePath] = xmlhttp.responseText;
} else {
cc.Assert("cocos2d:There was a problem retrieving the xml data:" + xmlhttp.statusText);
}
}
};
// load xml
xmlhttp.open("GET", filePath, false);
xmlhttp.send(null);
this.xmlList[filePath] = xmlhttp.responseText;
cc.Loader.shareLoader().onResLoaded();
} else {
alert("Your browser does not support XMLHTTP.");
cc.Assert("cocos2d:Your browser does not support XMLHTTP.");
}
},

Expand Down Expand Up @@ -223,9 +232,11 @@ cc.SAXParser = cc.Class.extend(/** @lends cc.SAXParser# */{
* @function
* @return {cc.SAXParser}
*/
cc.SAXParser.shareParser = function () {
if (!cc.shareParser) {
cc.shareParser = new cc.SAXParser();
cc.SAXParser.getInstance = function () {
if (!this._instance) {
this._instance = new cc.SAXParser();
}
return cc.shareParser;
return this._instance;
};

cc.SAXParser._instance = null;
6 changes: 3 additions & 3 deletions cocos2d/textures/CCTextureCache.js
Expand Up @@ -150,17 +150,17 @@ cc.TextureCache = cc.Class.extend(/** @lends cc.TextureCache# */{
cc.Assert(path != null, "TextureCache: path MUST not be null");
var texture = this.textures[path.toString()];
if (texture) {
cc.Loader.shareLoader().onResLoaded();
cc.Loader.getInstance().onResLoaded();
}
else {
texture = new Image();
var that = this;
texture.addEventListener("load", function () {

cc.Loader.shareLoader().onResLoaded();
cc.Loader.getInstance().onResLoaded();
});
texture.addEventListener("error", function () {
cc.Loader.shareLoader().onResLoadingErr(path);
cc.Loader.getInstance().onResLoadingErr(path);
});
texture.src = path;
this.textures[path.toString()] = texture;
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/tileMap_parallax_nodes/CCTMXXMLParser.js
Expand Up @@ -434,7 +434,7 @@ cc.TMXMapInfo = cc.SAXParser.extend(/** @lends cc.TMXMapInfo# */{
* @return {Element}
*/
parseXMLFile:function (tmxFile) {
var mapXML = cc.SAXParser.shareParser().tmxParse(tmxFile);
var mapXML = cc.SAXParser.getInstance().tmxParse(tmxFile);

// PARSE <map>
var map = mapXML.documentElement;
Expand Down
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -53,7 +53,7 @@ <h1><a href="index.html"><img src="tests/res/Images/cocos2dbanner.png"/></a>
<li><a href="HelloHTML5World/index.html">Hello World</a> <span
class="comment"> - Hello World for Cocos2d-HTML5</span></li>
<li><a href="tests/index.html">Test cases</a> <span class="comment"> - Engine Testcases</span></li>
<li><a href="Demo/demo.html">Demos</a> <span class="comment"> - Platform Demos</span></li>
<li><a href="Demo/index.html">Demos</a> <span class="comment"> - Platform Demos</span></li>
</ol>
<hr/>
<h2>Note</h2>
Expand Down
8 changes: 4 additions & 4 deletions template/main.js
Expand Up @@ -32,13 +32,13 @@ var cocos2dApp = cc.Application.extend({
cc.COCOS2D_DEBUG = this.config['COCOS2D_DEBUG'];
cc.setup(this.config['tag']);
cc.AudioEngine.getInstance().init("mp3,ogg");
cc.Loader.shareLoader().onloading = function () {
cc.LoaderScene.shareLoaderScene().draw();
cc.Loader.getInstance().onloading = function () {
cc.LoaderScene.getInstance().draw();
};
cc.Loader.shareLoader().onload = function () {
cc.Loader.getInstance().onload = function () {
cc.AppController.shareAppController().didFinishLaunchingWithOptions();
};
cc.Loader.shareLoader().preload(g_ressources);
cc.Loader.getInstance().preload(g_ressources);
},
applicationDidFinishLaunching:function () {
// initialize director
Expand Down

0 comments on commit 3445fb6

Please sign in to comment.