本文基于 Cocos Creator 2.4.1 撰寫(xiě)敦迄。
目錄:根目錄下
代碼code如下:
// PREDEFINE
// window may be undefined when first load engine from editor
var _global = typeof window === 'undefined' ? global : window;
//定義全局變量 獲取global 或者window ,因?yàn)檫\(yùn)行環(huán)境是非web 所以獲取到的是global齐莲。大家注意
/**
?* !#en
?* The main namespace of Cocos2d-JS, all engine core classes, functions, properties and constants are defined in this namespace.
?* !#zh
?* Cocos 引擎的主要命名空間纤子,引擎代碼中所有的類(lèi)胶台,函數(shù)沥阳,屬性和常量都在這個(gè)命名空間中定義。
?* @module cc
?* @main cc
?*/
_global.cc = _global.cc || {};//定義全局的cc變量
// For internal usage
cc.internal = cc.internal || {};//給cc下定義全局變量internal
require('./predefine');//定義全局配置變量哪痰,預(yù)定義 其中CC_DEV 等宏變量都在里面
// polyfills 基于系統(tǒng) 類(lèi)的拓展遂赠,為了處理兼容ie等瀏覽器 或者新增方便的用法
require('./polyfill/string');//比如string 拓展了startsWith endsWith trimLeft
require('./polyfill/misc');//數(shù)學(xué)函數(shù)拓展
require('./polyfill/array');//array拓展
require('./polyfill/object');//object拓展
require('./polyfill/array-buffer');//拓展isView方法
require('./polyfill/number');//parseFloat? parseInt
if (!(CC_EDITOR && Editor.isMainProcess)) {//CC_EDITOR 在預(yù)定義文件里面有定義,這個(gè)邏輯是針對(duì)web環(huán)境晌杰?
? ? require('./polyfill/typescript');//引入
}
require('./cocos2d/core/predefine');//基于cocos內(nèi)置的拓展
// LOAD COCOS2D ENGINE CODE
if (!(CC_EDITOR && Editor.isMainProcess)) {
? ? require('./cocos2d');//引入 ccGame 和 action 部分
}
// LOAD EXTENDS
require('./extends');
/*?
拓展部分包括
core
動(dòng)畫(huà)模塊
粒子
tilemap
web環(huán)境 模塊還會(huì)多引入video? webview? CCNodePool 和action
*/
if (CC_EDITOR) {
? ? if (Editor.isMainProcess) {
? ? ? ? Editor.versions['cocos2d'] = require('./package').version;
? ? }
}
/*?
導(dǎo)出global 下的cc 命名空間 */
module.exports = _global.cc;