diff --git a/CCBoot.js b/CCBoot.js index f423cd0847..bea23f68fd 100644 --- a/CCBoot.js +++ b/CCBoot.js @@ -784,10 +784,6 @@ cc.loader = { //+++++++++++++++++++++++++something about window events begin+++++++++++++++++++++++++++ (function(){ var win = window, hidden, visibilityChange; - cc.winEvents = { - hiddens : [], - shows : [] - }; if (typeof document.hidden !== "undefined") { hidden = "hidden"; visibilityChange = "visibilitychange"; @@ -803,16 +799,10 @@ cc.loader = { } var onHidden = function(){ - for(var i = 0, funcs = cc.winEvents.hiddens, li = funcs.length; i < li; i++){ - var func = funcs[i]; - if(func) func(); - } + cc.eventManager.dispatchEvent(cc.game._eventHide); }; var onShow = function(){ - for(var i = 0, funcs = cc.winEvents.shows, li = funcs.length; i < li; i++){ - var func = funcs[i]; - if(func) func(); - } + cc.eventManager.dispatchEvent(cc.game._eventShow); }; if (typeof document.addEventListener !== "undefined" && hidden) { @@ -825,9 +815,6 @@ cc.loader = { win.addEventListener("focus", onShow, false); } win = null; - onHidden = null; - onShow = null; - hidden = null; visibilityChange = null; })(); //+++++++++++++++++++++++++something about window events end+++++++++++++++++++++++++++++ @@ -1101,7 +1088,7 @@ cc._initSys = function(config, CONFIG_KEY){ * @type {string} */ sys.OS_ANDROID = "Android"; - sys.OS_UNKNOWN = "unknown"; + sys.OS_UNKNOWN = "Unknown"; sys.BROWSER_TYPE_WECHAT = "wechat"; sys.BROWSER_TYPE_ANDROID = "androidbrowser"; @@ -1143,7 +1130,6 @@ cc._initSys = function(config, CONFIG_KEY){ sys.isMobile = ua.indexOf('mobile') != -1 || ua.indexOf('android') != -1; - var currLanguage = nav.language; currLanguage = currLanguage ? currLanguage : nav.browserLanguage; currLanguage = currLanguage ? currLanguage.split("-")[0] : sys.LANGUAGE_ENGLISH; @@ -1216,7 +1202,6 @@ cc._initSys = function(config, CONFIG_KEY){ localStorage.removeItem("storage"); localStorage = null; }catch(e){ - if( e.name === "SECURITY_ERR" || e.name === "QuotaExceededError" ) { console.log("Warning: localStorage isn't enabled. Please confirm browser cookie or privacy option"); } @@ -1468,6 +1453,11 @@ cc.game = { DEBUG_MODE_WARN_FOR_WEB_PAGE : 5, DEBUG_MODE_ERROR_FOR_WEB_PAGE : 6, + EVENT_HIDE: "game_on_hide", + EVENT_SHOW: "game_on_show", + _eventHide: null, + _eventShow: null, + /** * Key of config * @constant @@ -1491,7 +1481,6 @@ cc.game = { _intervalId : null,//interval target of main - /** * Config of game * @type Object @@ -1566,6 +1555,8 @@ cc.game = { } self._paused = false; }, + + /** * Run game. */ @@ -1576,6 +1567,10 @@ cc.game = { if(!cc._supportRender) return; cc._setup(self.config[self.CONFIG_KEY.id]); self._runMainLoop(); + self._eventHide = self._eventHide || new cc.EventCustom(self.EVENT_HIDE); + self._eventHide.setUserData(this); + self._eventShow = self._eventShow || new cc.EventCustom(self.EVENT_SHOW); + self._eventShow.setUserData(this); self.onStart(); }); }else{ @@ -1584,6 +1579,10 @@ cc.game = { if(self._prepared){ cc._setup(self.config[self.CONFIG_KEY.id]); self._runMainLoop(); + self._eventHide = self._eventHide || new cc.EventCustom(self.EVENT_HIDE); + self._eventHide.setUserData(this); + self._eventShow = self._eventShow || new cc.EventCustom(self.EVENT_SHOW); + self._eventShow.setUserData(this); self.onStart(); clearInterval(self._checkPrepare); } diff --git a/cocos2d/audio/CCAudio.js b/cocos2d/audio/CCAudio.js index 21e6baf50f..75f4455b21 100644 --- a/cocos2d/audio/CCAudio.js +++ b/cocos2d/audio/CCAudio.js @@ -948,10 +948,10 @@ if (!cc.sys._supportWebAudio && cc.sys._supportMultipleAudio < 0){ cc.AudioEngine._getInstance = function () { if(!this._instance){ var ae = this._instance = cc.AudioEngineForSingle ? new cc.AudioEngineForSingle() : new cc.AudioEngine(); - cc.winEvents.hiddens.push(function(){ + cc.eventManager.addCustomListener(cc.game.EVENT_HIDE, function(){ ae._pausePlaying(); }); - cc.winEvents.shows.push(function(){ + cc.eventManager.addCustomListener(cc.game.EVENT_SHOW, function(){ ae._resumePlaying(); }); } @@ -1057,4 +1057,4 @@ cc._audioLoader._supportedAudioTypes = function() { } return arr; }(); -cc.loader.register(["mp3", "ogg", "wav", "mp4", "m4a"], cc._audioLoader); \ No newline at end of file +cc.loader.register(["mp3", "ogg", "wav", "mp4", "m4a"], cc._audioLoader); diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 9da4fab201..7a4a739c4a 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -185,23 +185,17 @@ cc.Director = cc.Class.extend(/** @lends cc.Director# */{ _eventAfterVisit: null, _eventAfterUpdate: null, - _isBlur:false, - /** * Constructor */ ctor:function () { var self = this; self._lastUpdate = Date.now(); - cc.winEvents.shows.push(function(){ + cc.eventManager.addCustomListener(cc.game.EVENT_SHOW, function(){ self._lastUpdate = Date.now(); }); }, - _resetLastUpdate:function () { - this._lastUpdate = Date.now(); - }, - /** * initializes cc.Director * @return {Boolean} diff --git a/cocos2d/core/event-manager/CCEventManager.js b/cocos2d/core/event-manager/CCEventManager.js index 4b631639c1..e7ce5257cd 100644 --- a/cocos2d/core/event-manager/CCEventManager.js +++ b/cocos2d/core/event-manager/CCEventManager.js @@ -118,6 +118,8 @@ cc.eventManager = { _isEnabled: true, _nodePriorityIndex: 0, + _internalCustomListenerIDs:[cc.game.EVENT_HIDE, cc.game.EVENT_SHOW], + _setDirtyForNode: function (node) { // Mark the node dirty only when there is an event listener associated with it. if (this._nodeListenersMap[node.__instanceId] != null) @@ -806,12 +808,11 @@ cc.eventManager = { * Removes all listeners */ removeAllListeners: function () { - var locListeners = this._listenersMap; - for (var selKey in locListeners) - this._removeListenersForListenerID(selKey); - - if (!this._inDispatch) - this._listenersMap = {}; + var locListeners = this._listenersMap, locInternalCustomEventIDs = this._internalCustomListenerIDs; + for (var selKey in locListeners){ + if(locInternalCustomEventIDs.indexOf(selKey) === -1) + this._removeListenersForListenerID(selKey); + } }, /** diff --git a/cocos2d/core/platform/CCConfig.js b/cocos2d/core/platform/CCConfig.js index 1eda02a15f..751ee6e95e 100644 --- a/cocos2d/core/platform/CCConfig.js +++ b/cocos2d/core/platform/CCConfig.js @@ -33,7 +33,7 @@ * @constant * @type String */ -cc.ENGINE_VERSION = "Cocos2d-html5-v2.2.2"; +cc.ENGINE_VERSION = "Cocos2d-html5-v3.0 alpha"; /** *
diff --git a/index.html b/index.html deleted file mode 100644 index b5ac4f320c..0000000000 --- a/index.html +++ /dev/null @@ -1,84 +0,0 @@ - - -
-
-While games written with Cocos2d-html5 should work offline, but some browsers won't allow this to happen. - Browsers that deny access to certain functions such as XMLHttpRequest that fails for "file:// " protocol, but - Cocos2d-html5 engine depend on this to read many files such as a .plist file.
- -Some versions of Firefox, Safari and Opera are notable exceptions.
- -If you wish to use other browsers, you need a webserver. It doesn't mean a seperate computer, you can download a - free webserver program to your computer. Here is some popular webserver program: -
- Once you install a webserver, go to your installation directory, there should be a directory called "htdocs" or - "www", place Cocos2d-html5 files in there. Then point your browser to http://localhost/. - -Cocos2d-html5 should now work without any errors
-