CocosCreator 源码-index.js讲解

本文基于 Cocos Creator 2.4.1 撰写。

目录:根目录下

代码code如下:

// PREDEFINE

// window may be undefined when first load engine from editor

var _global = typeof window === 'undefined' ? global : window;

//定义全局变量 获取global 或者window ,因为运行环境是非web 所以获取到的是global。大家注意

/**

 * !#en

 * The main namespace of Cocos2d-JS, all engine core classes, functions, properties and constants are defined in this namespace.

 * !#zh

 * Cocos 引擎的主要命名空间,引擎代码中所有的类,函数,属性和常量都在这个命名空间中定义。

 * @module cc

 * @main cc

 */

_global.cc = _global.cc || {};//定义全局的cc变量

// For internal usage

cc.internal = cc.internal || {};//给cc下定义全局变量internal

require('./predefine');//定义全局配置变量,预定义 其中CC_DEV 等宏变量都在里面

// polyfills 基于系统 类的拓展,为了处理兼容ie等浏览器 或者新增方便的用法

require('./polyfill/string');//比如string 拓展了startsWith endsWith trimLeft

require('./polyfill/misc');//数学函数拓展

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 在预定义文件里面有定义,这个逻辑是针对web环境?

    require('./polyfill/typescript');//引入

}

require('./cocos2d/core/predefine');//基于cocos内置的拓展

// LOAD COCOS2D ENGINE CODE

if (!(CC_EDITOR && Editor.isMainProcess)) {

    require('./cocos2d');//引入 ccGame 和 action 部分

}

// LOAD EXTENDS

require('./extends');

/* 

拓展部分包括

core

动画模块

粒子

tilemap

web环境 模块还会多引入video  webview  CCNodePool 和action

*/

if (CC_EDITOR) {

    if (Editor.isMainProcess) {

        Editor.versions['cocos2d'] = require('./package').version;

    }

}

/* 

导出global 下的cc 命名空间 */

module.exports = _global.cc;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值