diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 3467848d57..51fe959b21 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -45,9 +45,8 @@ cc.g_NumberOfDraws = 0; * The cc.director is also responsible for:
* - initializing the OpenGL context
* - setting the OpenGL pixel format (default on is RGB565)
- * - setting the OpenGL pixel format (default on is RGB565)
- * - setting the OpenGL buffer depth (default one is 0-bit)
- - setting the color for clear screen (default one is BLACK)
+ * - setting the OpenGL buffer depth (default on is 0-bit)
+ * - setting the color for clear screen (default one is BLACK)
* - setting the projection (default one is 3D)
* - setting the orientation (default one is Portrait)
*
@@ -65,7 +64,37 @@ cc.g_NumberOfDraws = 0; * - Only supports animation intervals of 1/60 1/30 & 1/15
*

* - * !#zh 导演类,负责创建和处理主窗口,以及管理场景执行。 + * !#zh + *

+ * 注意:用 cc.director 代替 cc.Director。
+ * cc.director 一个管理你的游戏的逻辑流程的单例对象。
+ * 由于 cc.director 是一个单例,你不需要调用任何构造函数或创建函数,
+ * 使用它的标准方法是通过调用:
+ * - cc.director.methodName(); + *
+ * 它创建和处理主窗口并且管理什么时候执行场景。
+ *
+ * cc.director 还负责:
+ * - 初始化 OpenGL 环境。
+ * - 设置OpenGL像素格式。(默认是 RGB565)
+ * - 设置OpenGL缓冲区深度 (默认是 0-bit)
+ * - 设置空白场景的颜色 (默认是 黑色)
+ * - 设置投影 (默认是 3D)
+ * - 设置方向 (默认是 Portrait)
+ *
+ * cc.director 设置了 OpenGL 默认环境
+ * - GL_TEXTURE_2D 启用。
+ * - GL_VERTEX_ARRAY 启用。
+ * - GL_COLOR_ARRAY 启用。
+ * - GL_TEXTURE_COORD_ARRAY 启用。
+ *

+ *

+ * cc.director 也同步定时器与显示器的刷新速率。 + *
+ * 特点和局限性:
+ * - 将计时器 & 渲染与显示器的刷新频率同步。
+ * - 只支持动画的间隔 1/60 1/30 & 1/15
+ *

* * @class Director */ @@ -195,9 +224,13 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** + * !#en * Converts a view coordinate to an WebGL coordinate
* Useful to convert (multi) touches coordinates to the current layout (portrait or landscape)
* Implementation can be found in CCDirectorWebGL. + * !#zh + * 将屏幕坐标转换为一个 OpenGL 坐标。
+ * 对于将(多点)触摸坐标转换为当前布局(横向或纵向)很有用。
* @method convertToGL * @param {Vec2} uiPoint * @return {Vec2} @@ -205,9 +238,13 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ convertToGL: null, /** - * Converts an WebGL coordinate to a view coordinate
+ * !#en + * Converts an OpenGL coordinate to a view coordinate
* Useful to convert node points to window points for calls such as glScissor
* Implementation can be found in CCDirectorWebGL. + * !#zh + * 将 OpenGL 坐标转换为屏幕坐标。
+ * 对于比如 glScissor 调用将 node 点转换到窗口点很有用。 * @method convertToUI * @param {Vec2} glPoint * @return {Vec2} @@ -280,9 +317,10 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** + * !#en * Returns the size in pixels of the surface. It could be different than the screen size.
* High-res devices might have a higher surface size than the screen size. - * + * !#zh 获取内容缩放比例。 * @method getContentScaleFactor * @return {Number} */ @@ -291,10 +329,14 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** + * !#en * This object will be visited after the main scene is visited.
* This object MUST implement the "visit" selector.
* Useful to hook a notification object. - * + * !#zh + * 这个对象将会在主场景渲染完后渲染。
+ * 这个对象必须实现 “visit” 功能。
+ * 对于 hook 一个通知节点很有用。 * @method getNotificationNode * @return {Node} */ @@ -303,9 +345,10 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** + * !#en * Returns the size of the WebGL view in points.
* It takes into account any possible rotation (device orientation) of the window. - * + * !#zh 获取视图的大小,以点为单位。 * @method getWinSize * @return {Size} */ @@ -314,10 +357,11 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** + * !#en * Returns the size of the OpenGL view in pixels.
* It takes into account any possible rotation (device orientation) of the window.
* On Mac winSize and winSizeInPixels return the same value. - * + * !#zh 获取视图大小,以像素为单位。 * @method getWinSizeInPixels * @return {Size} */ @@ -331,28 +375,32 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ */ /** - * Returns the visible size of the running scene. + * !#en Returns the visible size of the running scene. + * !#zh 获取运行场景的可见大小。 * @method getVisibleSize * @return {Size} */ getVisibleSize: null, /** - * Returns the visible origin of the running scene. + * !#en Returns the visible origin of the running scene. + * !#zh 获取可见视图的起始点,以点为单位。 * @method getVisibleOrigin * @return {Vec2} */ getVisibleOrigin: null, /** - * Returns the z eye, only available in WebGL mode. + * !#en Returns the z eye, only available in WebGL mode. + * !#zh 获取 Z eye,只有在WebGL的模式下可用。 * @method getZEye * @return {Number} */ getZEye: null, /** - * Pause the director's ticker + * !#en Pause the director's ticker. + * !#zh 暂停正在运行的场景。 * @method pause */ pause: function () { @@ -455,10 +503,16 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** + * !#en * Suspends the execution of the running scene, pushing it on the stack of suspended scenes.
* The new scene will be executed.
* Try to avoid big stacks of pushed scenes to reduce memory allocation.
* ONLY call it if there is a running scene. + * !#zh + * 暂停当前运行的场景,压入到暂停的场景栈中。
+ * 新场景将被执行。
+ * 尽量避免压入大场景,以减少内存分配。
+ * 只能在有运行场景时调用它。 * @method pushScene * @param {Scene} scene */ @@ -473,8 +527,10 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Run a scene. Replaces the running scene with a new one or enter the first scene. + * !#en + * Run a scene. Replaces the running scene with a new one or enter the first scene.
* The new scene will be launched immediately. + * !#zh 立刻切换指定场景。 * @method runSceneImmediate * @param {Scene} scene - The need run scene. * @param {Function} [onBeforeLoadScene] - The function invoked at the scene before loading. @@ -562,8 +618,10 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** + * !#en * Run a scene. Replaces the running scene with a new one or enter the first scene. * The new scene will be launched at the end of the current frame. + * !#zh 运行指定场景。 * @method runScene * @param {Scene} scene - The need run scene. * @param {Function} [onBeforeLoadScene] - The function invoked at the scene before loading. @@ -609,7 +667,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ // @Scene loading section /** - * Loads the scene by its name. + * !#en Loads the scene by its name. + * !#zh 通过场景名称进行加载场景。 * @method loadScene * @param {String} sceneName - The name of the scene to load. * @param {Function} [onLaunched] - callback, will be called after scene launched. @@ -706,7 +765,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Resume director after pause, if the current scene is not paused, nothing will happen. + * !#en Resume director after pause, if the current scene is not paused, nothing will happen. + * !#zh 恢复暂停场景, 如果当前场景没有暂停将没任何事情发生。 * @method resume */ resume: function () { @@ -736,16 +796,20 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** + * !#en * Enables or disables WebGL depth test.
* Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js + * !#zh 启用/禁用深度测试. * @method setDepthTest * @param {Boolean} on */ setDepthTest: null, /** + * !#en * set color for clear screen.
* Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js + * !#zh 设置空白场景的颜色值。 * @method setClearColor * @param {Color} clearColor */ @@ -834,56 +898,74 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** + * !#en * Sets the view, where everything is rendered, do not call this function.
* Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js. + * !#zh 设置 GLView。 * @method setOpenGLView * @param {View} openGLView */ setOpenGLView: null, /** + * !#en * Sets an OpenGL projection.
* Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js. + * !#zh 设置 OpenGL 投影。 * @method setProjection * @param {Number} projection */ setProjection: null, /** + * !#en * Update the view port.
* Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js. + * !#zh 设置 glViewport。 * @method setViewport */ setViewport: null, /** + * !#en * Get the View, where everything is rendered.
* Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js. + * !#zh + * 获取 GLView。 * @method getOpenGLView * @return {View} */ getOpenGLView: null, /** + * !#en * Sets an OpenGL projection.
* Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js. + * !#zh 获取 OpenGL 投影。 * @method getProjection * @return {Number} */ getProjection: null, /** + * !#en * Enables/disables OpenGL alpha blending.
* Implementation can be found in CCDirectorCanvas.js/CCDirectorWebGL.js. + * !#zh 启用/禁用 alpha blending * @method setAlphaBlending * @param {Boolean} on */ setAlphaBlending: null, /** + * !#en * Returns whether or not the replaced scene will receive the cleanup message.
* If the new scene is pushed, then the old scene won't receive the "cleanup" message.
* If the new scene replaces the old one, the it will receive the "cleanup" message. + * !#zh + * 更换场景时是否接收清理消息。
+ * 如果新场景是采用 push 方式进入的,那么旧的场景将不会接收到 “cleanup” 消息。
+ * 如果新场景取代旧的场景,它将会接收到 “cleanup” 消息。
* @method isSendCleanupToScene * @return {Boolean} */ @@ -892,8 +974,10 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** + * !#en * Returns current render Scene, normally you will never need to use this API. * In most case, you probably want to use `getScene` instead. + * !#zh 获取当前运行的场景。 * @method getRunningScene * @private * @return {Scene} @@ -903,19 +987,21 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Returns current logic Scene. + * !#en Returns current logic Scene. + * !#zh 获取当前场景。 + * @method getScene + * @return {Scene} * @example * // This will help you to get the Canvas node in scene * cc.director.getScene().getChildByName('Canvas'); - * @method getScene - * @return {Scene} */ getScene: function () { return this._scene; }, /** - * Returns the FPS value. + * !#en Returns the FPS value. + * !#zh 获取 FPS 数值。 * @method getAnimationInterval * @return {Number} */ @@ -924,7 +1010,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Returns whether or not to display the FPS informations. + * !#en Returns whether or not to display the FPS informations. + * !#zh 获取是否显示 FPS 信息。 * @method isDisplayStats * @return {Boolean} */ @@ -933,7 +1020,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Sets whether display the FPS on the bottom-left corner. + * !#en Sets whether display the FPS on the bottom-left corner. + * !#zh 设置是否在左下角显示 FPS。 * @method setDisplayStats * @param {Boolean} displayStats */ @@ -944,7 +1032,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Returns seconds per frame. + * !#en Returns seconds per frame. + * !#zh 获取每帧间隔几秒。 。 * @method getSecondsPerFrame * @return {Number} */ @@ -953,7 +1042,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Returns whether next delta time equals to zero + * !#en Returns whether next delta time equals to zero. + * !#zh 返回下一个 “delta time” 是否等于零。 * @method isNextDeltaTimeZero * @return {Boolean} */ @@ -962,7 +1052,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Returns whether or not the Director is paused + * !#en Returns whether or not the Director is paused. + * !#zh 获取 Director 是否暂停。 * @method isPaused * @return {Boolean} */ @@ -971,7 +1062,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Returns how many frames were called since the director started + * !#en Returns how many frames were called since the director started. + * !#zh 获取 director 开始以来游戏运行的总帧数。 * @method getTotalFrames * @return {Number} */ @@ -1024,7 +1116,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Returns the cc.Scheduler associated with this director. + * !#en Returns the cc.Scheduler associated with this director. + * !#zh 获取和 director 相关联的 cc.Scheduler。 * @method getScheduler * @return {Scheduler} */ @@ -1033,7 +1126,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Sets the cc.Scheduler associated with this director. + * !#en Sets the cc.Scheduler associated with this director. + * !#zh 设置和 director 相关联的 cc.Scheduler。 * @method setScheduler * @param {Scheduler} scheduler */ @@ -1044,7 +1138,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Returns the cc.ActionManager associated with this director. + * !#en Returns the cc.ActionManager associated with this director. + * !#zh 获取和 director 相关联的 cc.ActionManager(动作管理器). * @method getActionManager * @return {ActionManager} */ @@ -1052,7 +1147,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ return this._actionManager; }, /** - * Sets the cc.ActionManager associated with this director. + * !#en Sets the cc.ActionManager associated with this director. + * !#zh 设置和 director 相关联的 cc.ActionManager(动作管理器). * @method setActionManager * @param {ActionManager} actionManager */ @@ -1063,7 +1159,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Returns the cc.AnimationManager associated with this director. + * !#en Returns the cc.AnimationManager associated with this director. + * !#zh 获取和 director 相关联的 cc.AnimationManager(动画管理器). * @method getAnimationManager * @return {AnimationManager} */ @@ -1072,7 +1169,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ }, /** - * Returns the delta time since last frame. + * !#en Returns the delta time since last frame. + * !#zh 获取上一帧的 “delta time”。 * @method getDeltaTime * @return {Number} */ @@ -1090,18 +1188,20 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ cc.js.addon(cc.Director.prototype, EventTarget.prototype); /** - * The event projection changed of cc.Director + * !#en The event projection changed of cc.Director. + * !#zh cc.Director 投影变化的事件。 * @event cc.Director.EVENT_PROJECTION_CHANGED * @param {Event} event * @example * cc.director.on(cc.Director.EVENT_PROJECTION_CHANGED, function(event) { - * cc.log("Projection changed."); - * }); + * cc.log("Projection changed."); + * }); */ cc.Director.EVENT_PROJECTION_CHANGED = "director_projection_changed"; /** - * The event which will be triggered before loading a new scene + * !#en The event which will be triggered before loading a new scene. + * !#zh 加载新场景之前所触发的事件。 * @event cc.Director.EVENT_BEFORE_SCENE_LOADING * @param {Event} event * @param {Vec2} event.detail - The loading scene name @@ -1109,7 +1209,8 @@ cc.Director.EVENT_PROJECTION_CHANGED = "director_projection_changed"; cc.Director.EVENT_BEFORE_SCENE_LOADING = "director_before_scene_loading"; /* - * The event which will be triggered before launching a new scene + * !#en The event which will be triggered before launching a new scene. + * !#zh 运行新场景之前所触发的事件。 * @event cc.Director.EVENT_BEFORE_SCENE_LAUNCH * @param {Event} event * @param {Vec2} event.detail - New scene which will be launched @@ -1117,7 +1218,8 @@ cc.Director.EVENT_BEFORE_SCENE_LOADING = "director_before_scene_loading"; cc.Director.EVENT_BEFORE_SCENE_LAUNCH = "director_before_scene_launch"; /** - * The event which will be triggered after launching a new scene + * !#en The event which will be triggered after launching a new scene. + * !#zh 运行新场景之后所触发的事件。 * @event cc.Director.EVENT_AFTER_SCENE_LAUNCH * @param {Event} event * @param {Vec2} event.detail - New scene which is launched @@ -1125,14 +1227,16 @@ cc.Director.EVENT_BEFORE_SCENE_LAUNCH = "director_before_scene_launch"; cc.Director.EVENT_AFTER_SCENE_LAUNCH = "director_after_scene_launch"; /** - * The event which will be triggered at the beginning of every frame + * !#en The event which will be triggered at the beginning of every frame. + * !#zh 每个帧的开始时所触发的事件。 * @event cc.Director.EVENT_BEFORE_UPDATE * @param {Event} event */ cc.Director.EVENT_BEFORE_UPDATE = "director_before_update"; /** - * The event which will be triggered after components update + * !#en The event which will be triggered after components update. + * !#zh 组件 “update” 之后所触发的时间。 * @event cc.Director.EVENT_COMPONENT_UPDATE * @param {Event} event * @param {Vec2} event.detail - The delta time from last frame @@ -1140,7 +1244,8 @@ cc.Director.EVENT_BEFORE_UPDATE = "director_before_update"; cc.Director.EVENT_COMPONENT_UPDATE = "director_component_update"; /** - * The event which will be triggered after components late update + * !#en The event which will be triggered after components late update. + * !#zh 组件 “late update” 之后所触发的事件。 * @event cc.Director.EVENT_COMPONENT_LATE_UPDATE * @param {Event} event * @param {Vec2} event.detail - The delta time from last frame @@ -1148,29 +1253,34 @@ cc.Director.EVENT_COMPONENT_UPDATE = "director_component_update"; cc.Director.EVENT_COMPONENT_LATE_UPDATE = "director_component_late_update"; /** - * The event which will be triggered after engine and components update logic + * !#en The event which will be triggered after engine and components update logic. + * !#zh 将在引擎和组件 “update” 逻辑之后所触发的事件。 * @event cc.Director.EVENT_AFTER_UPDATE * @param {Event} event */ cc.Director.EVENT_AFTER_UPDATE = "director_after_update"; /** - * The event which will be triggered before visiting the rendering scene graph + * !#en The event which will be triggered before visiting the rendering scene graph. + * !#zh 这将访问渲染场景图之前所触发的事件。 * @event cc.Director.EVENT_BEFORE_VISIT * @param {Event} event */ cc.Director.EVENT_BEFORE_VISIT = "director_before_visit"; /** + * !#en * The event which will be triggered after visiting the rendering scene graph, - * the render queue is ready but not rendered at this point + * the render queue is ready but not rendered at this point. + * !#zh 这将访问渲染场景图之后所触发的事件,渲染队列已准备就绪,但在这一点上不会呈现。 * @event cc.Director.EVENT_AFTER_VISIT * @param {Event} event */ cc.Director.EVENT_AFTER_VISIT = "director_after_visit"; /** - * The event which will be triggered after the rendering process + * !#en The event which will be triggered after the rendering process. + * !#zh 这将在渲染过程之后所触发的事件。 * @event cc.Director.EVENT_AFTER_DRAW * @param {Event} event */ diff --git a/cocos2d/core/load-pipeline/loading-items.js b/cocos2d/core/load-pipeline/loading-items.js index ced9e16ade..dd2a48d392 100644 --- a/cocos2d/core/load-pipeline/loading-items.js +++ b/cocos2d/core/load-pipeline/loading-items.js @@ -27,19 +27,33 @@ var CallbacksInvoker = require('../platform/callbacks-invoker'); var JS = require('../platform/js'); /** - * LoadingItems is the manager of items in pipeline. - * It hold a map of items, each entry in the map is a url to object key value pair. - * Each item always contains the following property: - * - id: The identification of the item, usually it's identical to url - * - url: The url - * - type: The type, it's the extension name of the url by default, could be specified manually too - * - error: The error happened in pipeline will be stored in this property - * - content: The content processed by the pipeline, the final result will also be stored in this property - * - complete: The flag indicate whether the item is completed by the pipeline - * - states: An object stores the states of each pipe the item go through, the state can be: Pipeline.ItemState.WORKING | Pipeline.ItemState.ERROR | Pipeline.ItemState.COMPLETE + * !#en + * LoadingItems is the manager of items in pipeline.
+ * It hold a map of items, each entry in the map is a url to object key value pair.
+ * Each item always contains the following property:
+ * - id: The identification of the item, usually it's identical to url
+ * - url: The url
+ * - type: The type, it's the extension name of the url by default, could be specified manually too.
+ * - error: The error happened in pipeline will be stored in this property.
+ * - content: The content processed by the pipeline, the final result will also be stored in this property.
+ * - complete: The flag indicate whether the item is completed by the pipeline.
+ * - states: An object stores the states of each pipe the item go through, the state can be: Pipeline.ItemState.WORKING | Pipeline.ItemState.ERROR | Pipeline.ItemState.COMPLETE
+ *
+ * Item can hold other custom properties. + * !#zh + * LoadingItems 负责管理 pipeline 中的对象
+ * 它有一个 map 用来存放对象,在 map 对象中已 url 为 key 值。
+ * 每个对象都会包含下列属性:
+ * - id:该对象的标识,通常与 url 相同。
+ * - url:路径
+ * - type: 类型,它这是默认的 URL 的扩展名,可以手动指定赋值。
+ * - error:pipeline 中发生的错误将被保存在这个属性中。
+ * - content: pipeline 中处理的内容时,最终的结果也将被存储在这个属性中。
+ * - complete:该标志表明该对象是否通过 pipeline 完成。
+ * - states:该对象存储每个管道中对象经历的状态,状态可以是 Pipeline.ItemState.WORKING | Pipeline.ItemState.ERROR | Pipeline.ItemState.COMPLETE
+ *
+ * 对象可容纳其他自定义属性。 * - * Item can hold other custom properties - * * @class LoadingItems * @extends CallbacksInvoker */ @@ -47,28 +61,32 @@ var LoadingItems = function () { CallbacksInvoker.call(this); /** - * The map of all items + * !#en The map of all items. + * !#zh 存储所有对象。 * @property map * @type {Object} */ this.map = {}; /** - * The map of completed items + * !#en The map of completed items. + * !#zh 存储 map 中完成的对象。 * @property completed * @type {Object} */ this.completed = {}; /** - * Total count of all items + * !#en Total count of all items. + * !#zh 所有对象的总数。 * @property totalCount * @type {Number} */ this.totalCount = 0; /** - * Total count of completed items + * !#en Total count of completed items. + * !#zh 所有完成对象的总数。 * @property completedCount * @type {Number} */ @@ -100,7 +118,8 @@ JS.mixin(LoadingItems.prototype, CallbacksInvoker.prototype, { }, /** - * Check whether an item is completed + * !#en Check whether an item is completed. + * !#zh 检查指定对象是否完成。 * @param {String} id The item's id. * @return {Boolean} */ @@ -109,7 +128,8 @@ JS.mixin(LoadingItems.prototype, CallbacksInvoker.prototype, { }, /** - * Check whether an item exists + * !#en Check whether an item exists. + * !#zh 检查指定对象是否存在。 * @param {String} id The item's id. * @return {Boolean} */ @@ -118,7 +138,8 @@ JS.mixin(LoadingItems.prototype, CallbacksInvoker.prototype, { }, /** - * Returns the content of an internal item + * !#en Returns the content of an internal item. + * !#zh 获取指定对象的内容。 * @param {String} id The item's id. * @return {Object} */ @@ -128,7 +149,8 @@ JS.mixin(LoadingItems.prototype, CallbacksInvoker.prototype, { }, /** - * Returns the error of an internal item + * !#en Returns the error of an internal item. + * !#zh 获取指定对象的错误信息。 * @param {String} id The item's id. * @return {Object} */ @@ -138,7 +160,8 @@ JS.mixin(LoadingItems.prototype, CallbacksInvoker.prototype, { }, /** - * Add a listener for an item, the callback will be invoked when the item is completed. + * !#en Add a listener for an item, the callback will be invoked when the item is completed. + * !#zh 向对象添加监听器,回调将在对象完成时被调用。 * @method addListener * @param {String} key * @param {Function} callback - can be null @@ -148,8 +171,12 @@ JS.mixin(LoadingItems.prototype, CallbacksInvoker.prototype, { addListener: CallbacksInvoker.prototype.add, /** - * Check if the specified key has any registered callback. + * !#en + * Check if the specified key has any registered callback.
* If a callback is also specified, it will only return true if the callback is registered. + * !#zh + * 检查是否有任何指定的键的注册回调。
+ * 如果同时还指定了一个回调方法,并且回调有注册,它只会返回 true。 * @method hasListener * @param {String} key * @param {Function} [callback] @@ -159,8 +186,12 @@ JS.mixin(LoadingItems.prototype, CallbacksInvoker.prototype, { hasListener: CallbacksInvoker.prototype.has, /** - * Removes a listener. + * !#en + * Removes a listener.
* It will only remove when key, callback, target all match correctly. + * !#zh + * 移除监听器。
+ * 它只会删除匹配所有 key, callback, target 的监听器。 * @method remove * @param {String} key * @param {Function} callback @@ -170,7 +201,10 @@ JS.mixin(LoadingItems.prototype, CallbacksInvoker.prototype, { removeListener: CallbacksInvoker.prototype.remove, /** - * Removes all callbacks registered in a certain event type or all callbacks registered with a certain target + * !#en + * Removes all callbacks registered in a certain event + * type or all callbacks registered with a certain target. + * !#zh 删除指定目标的所有回调。 * @method removeAllListeners * @param {String|Object} key - The event key to be removed or the target to be removed */ diff --git a/cocos2d/core/load-pipeline/pipeline.js b/cocos2d/core/load-pipeline/pipeline.js index 93930c16a1..9a7a2889ec 100644 --- a/cocos2d/core/load-pipeline/pipeline.js +++ b/cocos2d/core/load-pipeline/pipeline.js @@ -160,30 +160,44 @@ function getXMLHttpRequest () { } /** - * A pipeline describes a sequence of manipulations, each manipulation is called a pipe. - * It's designed for loading process, so items should be urls, and the url will be the identity of each item during the process. - * A list of items can flow in the pipeline and it will output the results of all pipes. - * They flow in the pipeline like water in tubes, they go through pipe by pipe separately. + * !#en + * A pipeline describes a sequence of manipulations, each manipulation is called a pipe.
+ * It's designed for loading process, so items should be urls, and the url will be the identity of each item during the process.
+ * A list of items can flow in the pipeline and it will output the results of all pipes.
+ * They flow in the pipeline like water in tubes, they go through pipe by pipe separately.
* Finally all items will flow out the pipeline and the process is finished. - * + * + * !#zh + * pipeline 描述了一系列的操作,每一个操作被称为 pipe。
+ * 它设计来作处理加载,所以 item 应该是 url,并且该 url 将是在处理中的每个 item 的身份标识。
+ * 一个 item 列表可以在 pipeline 中流动,它将输出所有 pipe 的结果。
+ * 它们穿过 pipeline 就像水在管子里流动,而且每个 pipe 单独穿过。
+ * 最后所有 items 将流出 pipeline 而且这过程将结束。 * @class Pipeline */ /** - * Constructor, pass an array of pipes to construct a new Pipeline, the pipes will be chained in the given order. - * A pipe is an object which must contain an `id` in string and a `handle` function, the id must be unique in the pipeline. + * !#en + * Constructor, pass an array of pipes to construct a new Pipeline, + * the pipes will be chained in the given order.
+ * A pipe is an object which must contain an `id` in string and a `handle` function, + * the id must be unique in the pipeline.
* It can also include `async` property to identify whether it's an asynchronous process. + * !#zh + * 构造函数,通过一系列的 pipe 来构造一个新的 pipeline,pipes 将在给定的顺序中被锁定。
+ * 一个 pipe 是一个对象,它包含了字符串的 ‘id’ 和 ‘handle’ 函数,在 pipeline 中 id 必须是唯一的。
+ * 它还可以包括 ‘async’ 属性以确定它是否是一个异步进程。 + * + * @method Pipeline + * @param {Array} pipes * @example * var pipeline = new Pipeline([ * { - * id: 'Downloader', - * handle: function (item, callback) {}, + * id: 'Downloader', + * handle: function (item, callback) {}, * async: true * }, * {id: 'Parser', handle: function (item) {}, async: false} * ]); - * - * @method Pipeline - * @param {Array} pipes */ var Pipeline = function (pipes) { this._pipes = pipes; @@ -209,9 +223,12 @@ Pipeline.getXMLHttpRequest = getXMLHttpRequest; JS.mixin(Pipeline.prototype, { /** - * Insert a new pipe at the given index of the pipeline. + * !#en + * Insert a new pipe at the given index of the pipeline.
* A pipe must contain an `id` in string and a `handle` function, the id must be unique in the pipeline. - * + * !#zh + * 插入一个新的 pipe 在给定索引的 pipeline。
+ * 一个 pipe 必须包含一个字符串 ‘id’ 和 ‘handle’ 函数,该 id 在 pipeline 必须是唯一标识。 * @method insertPipe * @param {Object} pipe The pipe to be inserted * @param {Number} index The index to insert @@ -235,9 +252,12 @@ JS.mixin(Pipeline.prototype, { }, /** - * Add a new pipe at the end of the pipeline. + * !#en + * Add a new pipe at the end of the pipeline.
* A pipe must contain an `id` in string and a `handle` function, the id must be unique in the pipeline. - * + * !#zh + * 添加一个新的 pipe 到 pipeline 尾部。
+ * 该 pipe 必须包含一个字符串 ‘id’ 和 ‘handle’ 函数,该 id 在 pipeline 必须是唯一标识。 * @method appendPipe * @param {Object} pipe The pipe to be appended */ @@ -254,12 +274,23 @@ JS.mixin(Pipeline.prototype, { }, /** - * Let new items flow into the pipeline. - * Each item can be a simple url string or an object, - * if it's an object, it must contain `id` property. - * You can specify its type by `type` property, by default, the type is the extension name in `src`. - * By adding a `skips` property including pipe ids, you can skip these pipe. - * The object can contain any supplementary property as you want. + * !#en + * Let new items flow into the pipeline.
+ * Each item can be a simple url string or an object, + * if it's an object, it must contain `id` property.
+ * You can specify its type by `type` property, by default, the type is the extension name in `src`.
+ * By adding a `skips` property including pipe ids, you can skip these pipe.
+ * The object can contain any supplementary property as you want.
+ * !#zh + * 让新的的 item 流入 pipeline 中。
+ * 每个 item 可以是一个简单的 url 字符串或一个对象, + * 如果它是一个对象,他必须要包含 ‘id’ 属性。
+ * 你可以指定它的 ‘type’ 属性类型,默认情况下,该类型是 ‘src’ 的后缀名。
+ * 通过添加一个 包含 ‘skips’ 属性的 pipe,你可以跳过这些 pipe。
+ * 该对象可以包含任何附加属性。 + * @method flowIn + * @param {Array} urlList + * @return {Array} Items accepted by the pipeline * @example * pipeline.flowIn([ * 'res/Background.png', @@ -270,10 +301,6 @@ JS.mixin(Pipeline.prototype, { * skips: ['Downloader'] * } * ]); - * - * @method flowIn - * @param {Array} urlList - * @return {Array} Items accepted by the pipeline */ flowIn: function (urlList) { var items = [], i, url, item; @@ -308,12 +335,17 @@ JS.mixin(Pipeline.prototype, { }, /** - * Let new items flow into the pipeline and give a callback when the list of items are all completed. - * This is for loading dependencies for an existing item in flow, usually used in a pipe logic. - * For example, we have a loader for scene configuration file in JSON, the scene will only be fully loaded - * after all its dependencies are loaded, then you will need to use function to flow in all dependencies + * !#en + * Let new items flow into the pipeline and give a callback when the list of items are all completed.
+ * This is for loading dependencies for an existing item in flow, usually used in a pipe logic.
+ * For example, we have a loader for scene configuration file in JSON, the scene will only be fully loaded
+ * after all its dependencies are loaded, then you will need to use function to flow in all dependencies
* found in the configuration file, and finish the loader pipe only after all dependencies are loaded (in the callback). - * + * !#zh + * 让新 items 流入 pipeline 并且当 item 列表完成时进行回调函数。
+ * 这是现有的加载依赖项流,通常用于 pipe 逻辑。
+ * 例如:
+ * 我们需要加载一个场景配置的 JSON 文件,该场景会将所有的依赖项全部都加载完毕以后,进行回调表示加载完毕。 * @method flowInDeps * @param {Array} urlList * @param {Function} callback @@ -406,13 +438,20 @@ JS.mixin(Pipeline.prototype, { }, /** - * Copy the item states from one source item to all destination items. - * It's quite useful when a pipe generate new items from one source item, - * then you should flowIn these generated items into pipeline, - * but you probably want them to skip all pipes the source item already go through, - * you can achieve it with this API. - * + * !#en + * Copy the item states from one source item to all destination items.
+ * It's quite useful when a pipe generate new items from one source item,
+ * then you should flowIn these generated items into pipeline,
+ * but you probably want them to skip all pipes the source item already go through,
+ * you can achieve it with this API.
+ *
* For example, an unzip pipe will generate more items, but you won't want them to pass unzip or download pipe again. + * !#zh + * 复制 item 状态从一个源 item 对所有目标 items。
+ * 新 items 从一个源 item 的 pipe 生成时很有用,
+ * 那么你应该 flowIn 这些生成的 item 进入 pipeline,
+ * 但是你可能希望他们源 item 已经通过并跳过所有 pipes,
+ * 你可以用这个API实现它。 * @method copyItemStates * @param {Object} srcItem The source item * @param {Array|Object} dstItems A single destination item or an array of destination items @@ -428,7 +467,8 @@ JS.mixin(Pipeline.prototype, { }, /** - * Returns whether the pipeline is flowing (contains item) currently. + * !#en Returns whether the pipeline is flowing (contains item) currently. + * !#zh 获取 pipeline 当前是否是流动的。 * @method isFlowing * @return {Boolean} */ @@ -437,7 +477,8 @@ JS.mixin(Pipeline.prototype, { }, /** - * Returns all items in pipeline. + * !#en Returns all items in pipeline. + * !#zh 获取 pipeline 中的所有 items。 * @method getItems * @return {LoadingItems} */ @@ -446,7 +487,8 @@ JS.mixin(Pipeline.prototype, { }, /** - * Returns an item in pipeline. + * !#en Returns an item in pipeline. + * !#zh 获取指定 item。 * @method getItems * @return {LoadingItems} */ @@ -455,7 +497,8 @@ JS.mixin(Pipeline.prototype, { }, /** - * Removes an item in pipeline, no matter it's in progress or completed. + * !#en Removes an item in pipeline, no matter it's in progress or completed. + * !#zh 移除指定 item,无论是进行时还是已完成。 * @method removeItem * @return {Boolean} succeed or not */ @@ -474,7 +517,8 @@ JS.mixin(Pipeline.prototype, { }, /** - * Clear the current pipeline, this function will clean up the items. + * !#en Clear the current pipeline, this function will clean up the items. + * !#zh 清空当前 pipeline,该函数将清理 items。 * @method clear */ clear: function () { @@ -495,21 +539,27 @@ JS.mixin(Pipeline.prototype, { }, /** - * This is a callback which will be invoked while an item flow out the pipeline, you should overwrite this function. + * !#en This is a callback which will be invoked while an item flow out the pipeline, you should overwrite this function. + * !#zh 这个回调函数将 item 流出 pipeline 时被调用,你应该重写该函数。 + * @method onProgress + * @param {Number} completedCount The number of the items that are already completed. + * @param {Number} totalCount The total number of the items. + * @param {Object} item The latest item which flow out the pipeline. * @example * pipeline.onProgress = function (completedCount, totalCount, item) { * var progress = (100 * completedCount / totalCount).toFixed(2); * cc.log(progress + '%'); * } - * @method onProgress - * @param {Number} completedCount The number of the items that are already completed. - * @param {Number} totalCount The total number of the items. - * @param {Object} item The latest item which flow out the pipeline. */ onProgress: null, /** - * This is a callback which will be invoked while all items flow out the pipeline, you should overwirte this function. + * !#en This is a callback which will be invoked while all items flow out the pipeline, + * you should overwirte this function. + * !#zh 该函数将在所有 item 流出 pipeline 时被调用,你应该重写该函数。 + * @method onComplete + * @param {Array} error All errored urls will be stored in this array, if no error happened, then it will be null + * @param {LoadingItems} items All items. * @example * pipeline.onComplete = function (error, items) { * if (error) @@ -517,9 +567,6 @@ JS.mixin(Pipeline.prototype, { * else * cc.log('Completed ' + items.totalCount + ' items'); * } - * @method onComplete - * @param {Array} error All errored urls will be stored in this array, if no error happened, then it will be null - * @param {LoadingItems} items All items. */ onComplete: null });