• Director 类型
    • 索引
      • 属性(properties)
      • 方法
      • 事件
  • Details
    • 属性(properties)
      • EVENT_PROJECTION_CHANGED
      • EVENT_BEFORE_SCENE_LOADING
      • EVENT_BEFORE_SCENE_LAUNCH
      • EVENT_AFTER_SCENE_LAUNCH
      • EVENT_BEFORE_UPDATE
      • EVENT_AFTER_UPDATE
      • EVENT_BEFORE_VISIT
      • EVENT_AFTER_VISIT
      • EVENT_BEFORE_DRAW
      • EVENT_AFTER_DRAW
      • PROJECTION_2D
      • PROJECTION_3D
      • PROJECTION_CUSTOM
      • PROJECTION_DEFAULT
        • 参数列表
      • convertToUI
        • 参数列表
      • end
      • getWinSize
      • getWinSizeInPixels
      • pause
      • runSceneImmediate
        • 参数列表
      • runScene
        • 参数列表
      • loadScene
        • 参数列表
      • preloadScene
        • 参数列表
      • _loadSceneByUuid
        • 参数列表
      • resume
      • setDepthTest
        • 参数列表
      • setClearColor
        • 参数列表
      • getRunningScene
      • getScene
      • 示例
      • getAnimationInterval
      • setAnimationInterval
        • 参数列表
      • getDeltaTime
      • getTotalFrames
      • isPaused
      • getScheduler
      • setScheduler
        • 参数列表
      • getActionManager
      • setActionManager
        • 参数列表
      • getCollisionManager
      • getPhysicsManager
      • hasEventListener
        • 参数列表
      • on
        • 参数列表
      • 示例
      • off
        • 参数列表
      • 示例
      • targetOff
        • 参数列表
      • once
        • 参数列表
      • 示例
      • emit
        • 参数列表
      • 示例
      • dispatchEvent
        • 参数列表
    • 事件
  • cc.Director.EVENT_BEFORE_SCENE_LOADING Event
  • 索引
  • Details
  • cc.Director.EVENT_AFTER_SCENE_LAUNCH Event
  • 索引
  • Details
  • cc.Director.EVENT_BEFORE_UPDATE Event
  • 索引
  • Details
  • cc.Director.EVENT_AFTER_UPDATE Event
  • 索引
  • Details
  • cc.Director.EVENT_BEFORE_DRAW Event
  • 索引
  • Details
  • cc.Director.EVENT_AFTER_DRAW Event
  • 索引
  • Details

    Director 类型

    继承于 EventTarget

    模块: cc

    注意:用 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。

    索引

    属性(properties)
    • EVENT_PROJECTION_CHANGED String cc.Director 投影变化的事件。
    • EVENT_BEFORE_SCENE_LOADING String 加载新场景之前所触发的事件。
    • EVENT_BEFORE_SCENE_LAUNCH String 运行新场景之前所触发的事件。
    • EVENT_AFTER_SCENE_LAUNCH String 运行新场景之后所触发的事件。
    • EVENT_BEFORE_UPDATE String 每个帧的开始时所触发的事件。
    • EVENT_AFTER_UPDATE String 将在引擎和组件 “update” 逻辑之后所触发的事件。
    • EVENT_BEFORE_VISIT String 这个事件从 v2.0 开始被废弃,请直接使用 cc.Director.EVENT_BEFORE_DRAW
    • EVENT_AFTER_VISIT String 这个事件从 v2.0 开始被废弃,请直接使用 cc.Director.EVENT_BEFORE_DRAW
    • EVENT_BEFORE_DRAW String 渲染过程之前所触发的事件。
    • EVENT_AFTER_DRAW String 渲染过程之后所触发的事件。
    • PROJECTION_2D Number Constant for 2D projection (orthogonal projection)
    • PROJECTION_3D Number Constant for 3D projection with a fovy=60, znear=0.5f and zfar=1500.
    • PROJECTION_CUSTOM Number Constant for custom projection, if cc.Director's projection set to it, it calls "updateProjection" on the projection delegate.
    • PROJECTION_DEFAULT Number Constant for default projection of cc.Director, default projection is 2D projection
    方法
    • convertToGL 将触摸点的屏幕坐标转换为 WebGL View 下的坐标。
    • convertToUI 将触摸点的 WebGL View 坐标转换为屏幕坐标。
    • end End the life of director in the next frame
    • getWinSize 获取视图的大小,以点为单位。
    • getWinSizeInPixels 获取视图大小,以像素为单位(这里的像素指的是资源分辨率。
    • pause 暂停正在运行的场景,该暂停只会停止游戏逻辑执行,但是不会停止渲染和 UI 响应。
    • runSceneImmediate 立刻切换指定场景。
    • runScene 运行指定场景。
    • loadScene 通过场景名称进行加载场景。
    • preloadScene 预加载场景,你可以在任何时候调用这个方法。
    • _loadSceneByUuid Loads the scene by its uuid.
    • resume 恢复暂停场景的游戏逻辑,如果当前场景没有暂停将没任何事情发生。
    • setDepthTest 启用/禁用深度测试(在 Canvas 渲染模式下不会生效)。
    • setClearColor 设置场景的默认擦除颜色。
    • getRunningScene 获取当前逻辑场景。
    • getScene 获取当前逻辑场景。
    • getAnimationInterval 获取单位帧执行时间。
    • setAnimationInterval Sets animation interval, this doesn't control the main loop….
    • getDeltaTime 获取上一帧的增量时间。
    • getTotalFrames 获取 director 启动以来游戏运行的总帧数。
    • isPaused 是否处于暂停状态。
    • getScheduler 获取和 director 相关联的 cc.Scheduler。
    • setScheduler 设置和 director 相关联的 cc.Scheduler。
    • getActionManager 获取和 director 相关联的 cc.ActionManager(动作管理器)。
    • setActionManager 设置和 director 相关联的 cc.ActionManager(动作管理器)。
    • getCollisionManager 获取和 director 相关联的 cc.CollisionManager (碰撞管理器)。
    • getPhysicsManager 返回与 director 相关联的 cc.PhysicsManager (物理管理器)。
    • hasEventListener 检查事件目标对象是否有为特定类型的事件注册的回调。
    • on 注册事件目标的特定事件类型回调。
    • off 删除之前用同类型,回调,目标或 useCapture 注册的事件监听器,如果只传递 type,将会删除 type 类型的所有事件监听器。
    • targetOff 在当前 EventTarget 上删除指定目标(target 参数)注册的所有事件监听器。
    • once 注册事件目标的特定事件类型回调,回调会在第一时间被触发后删除自身。
    • emit 通过事件名发送自定义事件
    • dispatchEvent 通过事件对象派发事件
    事件
    • cc.Director.EVENT_BEFORE_SCENE_LOADING 加载新场景之前所触发的事件。
    • cc.Director.EVENT_AFTER_SCENE_LAUNCH 运行新场景之后所触发的事件。
    • cc.Director.EVENT_BEFORE_UPDATE 每个帧的开始时所触发的事件。
    • cc.Director.EVENT_AFTER_UPDATE 将在引擎和组件 “update” 逻辑之后所触发的事件。
    • cc.Director.EVENT_BEFORE_DRAW 渲染过程之前所触发的事件。
    • cc.Director.EVENT_AFTER_DRAW 渲染过程之后所触发的事件。

    Details

    属性(properties)

    EVENT_PROJECTION_CHANGED
    cc.Director 投影变化的事件。从 v2.0 开始这个事件不会再被触发
    metadescription
    类型String
    定义于cocos2d/core/CCDirector.js:980
    废弃(Deprecated)since v2.0
    EVENT_BEFORE_SCENE_LOADING
    加载新场景之前所触发的事件。
    metadescription
    类型String
    定义于cocos2d/core/CCDirector.js:996
    EVENT_BEFORE_SCENE_LAUNCH
    运行新场景之前所触发的事件。
    metadescription
    类型String
    定义于cocos2d/core/CCDirector.js:1011
    EVENT_AFTER_SCENE_LAUNCH
    运行新场景之后所触发的事件。
    metadescription
    类型String
    定义于cocos2d/core/CCDirector.js:1026
    EVENT_BEFORE_UPDATE
    每个帧的开始时所触发的事件。
    metadescription
    类型String
    定义于cocos2d/core/CCDirector.js:1040
    EVENT_AFTER_UPDATE
    将在引擎和组件 “update” 逻辑之后所触发的事件。
    metadescription
    类型String
    定义于cocos2d/core/CCDirector.js:1054
    EVENT_BEFORE_VISIT
    这个事件从 v2.0 开始被废弃,请直接使用 cc.Director.EVENT_BEFORE_DRAW
    metadescription
    类型String
    定义于cocos2d/core/CCDirector.js:1063
    废弃(Deprecated)since v2.0
    EVENT_AFTER_VISIT
    这个事件从 v2.0 开始被废弃,请直接使用 cc.Director.EVENT_BEFORE_DRAW
    metadescription
    类型String
    定义于cocos2d/core/CCDirector.js:1073
    废弃(Deprecated)since v2.0
    EVENT_BEFORE_DRAW
    渲染过程之前所触发的事件。
    metadescription
    类型String
    定义于cocos2d/core/CCDirector.js:1088
    EVENT_AFTER_DRAW
    渲染过程之后所触发的事件。
    metadescription
    类型String
    定义于cocos2d/core/CCDirector.js:1102
    PROJECTION_2D
    Constant for 2D projection (orthogonal projection)
    metadescription
    类型Number
    定义于cocos2d/core/CCDirector.js:1113
    废弃(Deprecated)since v2.0
    PROJECTION_3D
    Constant for 3D projection with a fovy=60, znear=0.5f and zfar=1500.
    metadescription
    类型Number
    定义于cocos2d/core/CCDirector.js:1123
    废弃(Deprecated)since v2.0
    PROJECTION_CUSTOM
    Constant for custom projection, if cc.Director's projection set to it, it calls "updateProjection" on the projection delegate.
    metadescription
    类型Number
    定义于cocos2d/core/CCDirector.js:1133
    废弃(Deprecated)since v2.0
    PROJECTION_DEFAULT
    Constant for default projection of cc.Director, default projection is 2D projection
    metadescription
    类型Number
    定义于cocos2d/core/CCDirector.js:1143
    废弃(Deprecated)since v2.0



    #### 方法



    ##### convertToGL


    将触摸点的屏幕坐标转换为 WebGL View 下的坐标。

    metadescription
    返回Vec2
    定义于cocos2d/core/CCDirector.js:230
    废弃(Deprecated)since v2.0
    参数列表
    • uiPoint Vec2
    convertToUI

    将触摸点的 WebGL View 坐标转换为屏幕坐标。

    metadescription
    返回Vec2
    定义于cocos2d/core/CCDirector.js:252
    废弃(Deprecated)since v2.0
    参数列表
    • glPoint Vec2
    end

    End the life of director in the next frame

    metadescription
    定义于cocos2d/core/CCDirector.js:281
    getWinSize

    获取视图的大小,以点为单位。

    metadescription
    返回Size
    定义于cocos2d/core/CCDirector.js:289
    废弃(Deprecated)since v2.0
    getWinSizeInPixels

    获取视图大小,以像素为单位(这里的像素指的是资源分辨率。如果要获取屏幕物理分辨率,需要用 cc.view.getFrameSize())

    metadescription
    返回Size
    定义于cocos2d/core/CCDirector.js:302
    废弃(Deprecated)since v2.0
    pause

    暂停正在运行的场景,该暂停只会停止游戏逻辑执行,但是不会停止渲染和 UI 响应。如果想要更彻底得暂停游戏,包含渲染,音频和事件,请使用 Game.pause。

    metadescription
    定义于cocos2d/core/CCDirector.js:319
    runSceneImmediate

    立刻切换指定场景。

    metadescription
    定义于cocos2d/core/CCDirector.js:403
    参数列表
    • scene Scene The need run scene.
    • onBeforeLoadScene Function The function invoked at the scene before loading.
    • onLaunched Function The function invoked at the scene after launch.
    runScene

    运行指定场景。

    metadescription
    定义于cocos2d/core/CCDirector.js:482
    参数列表
    • scene Scene The need run scene.
    • onBeforeLoadScene Function The function invoked at the scene before loading.
    • onLaunched Function The function invoked at the scene after launch.
    loadScene

    通过场景名称进行加载场景。

    metadescription
    返回Boolean
    定义于cocos2d/core/CCDirector.js:539
    参数列表
    • sceneName String The name of the scene to load.
    • onLaunched Function callback, will be called after scene launched.
    preloadScene

    预加载场景,你可以在任何时候调用这个方法。调用完后,你仍然需要通过 cc.director.loadScene 来启动场景,因为这个方法不会执行场景加载操作。就算预加载还没完成,你也可以直接调用 cc.director.loadScene,加载完成后场景就会启动。

    metadescription
    定义于cocos2d/core/CCDirector.js:567
    参数列表
    • sceneName String The name of the scene to preload.
    • onProgress Function callback, will be called when the load progression change.
      • completedCount Number The number of the items that are already completed
      • totalCount Number The total number of the items
      • item Object The latest item which flow out the pipeline
    • onLoaded Function callback, will be called after scene loaded.
      • error Error null or the error object.
    _loadSceneByUuid

    Loads the scene by its uuid.

    metadescription
    定义于cocos2d/core/CCDirector.js:613
    参数列表
    • uuid String the uuid of the scene asset to load
    • onLaunched Function
    • onUnloaded Function
    • dontRunScene Boolean Just download and initialize the scene but will not launch it,
    1. only take effect in the Editor.
    resume

    恢复暂停场景的游戏逻辑,如果当前场景没有暂停将没任何事情发生。

    metadescription
    定义于cocos2d/core/CCDirector.js:676
    setDepthTest

    启用/禁用深度测试(在 Canvas 渲染模式下不会生效)。

    metadescription
    定义于cocos2d/core/CCDirector.js:695
    废弃(Deprecated)since v2.0
    参数列表
    • on Boolean
    setClearColor

    设置场景的默认擦除颜色。支持全透明,但不支持透明度为中间值。要支持全透明需手工开启 cc.macro.ENABLE_TRANSPARENT_CANVAS。

    metadescription
    定义于cocos2d/core/CCDirector.js:711
    废弃(Deprecated)since v2.0
    参数列表
    • clearColor Color
    getRunningScene

    获取当前逻辑场景。

    metadescription
    返回Scene
    定义于cocos2d/core/CCDirector.js:729
    废弃(Deprecated)since v2.0
    getScene

    获取当前逻辑场景。

    metadescription
    返回Scene
    定义于cocos2d/core/CCDirector.js:741
    示例
    1. // This will help you to get the Canvas node in scene
    2. cc.director.getScene().getChildByName('Canvas');
    getAnimationInterval

    获取单位帧执行时间。请使用 Game.setFrameRate 来控制游戏帧率。

    metadescription
    返回Number
    定义于cocos2d/core/CCDirector.js:754
    废弃(Deprecated)since v2.0
    setAnimationInterval

    Sets animation interval, this doesn't control the main loop.To control the game's frame rate overall, please use Game.setFrameRate

    metadescription
    定义于cocos2d/core/CCDirector.js:765
    废弃(Deprecated)since v2.0
    参数列表
    • value Number The animation interval desired.
    getDeltaTime

    获取上一帧的增量时间。

    metadescription
    返回Number
    定义于cocos2d/core/CCDirector.js:776
    getTotalFrames

    获取 director 启动以来游戏运行的总帧数。

    metadescription
    返回Number
    定义于cocos2d/core/CCDirector.js:786
    isPaused

    是否处于暂停状态。

    metadescription
    返回Boolean
    定义于cocos2d/core/CCDirector.js:796
    getScheduler

    获取和 director 相关联的 cc.Scheduler。

    metadescription
    返回Scheduler
    定义于cocos2d/core/CCDirector.js:806
    setScheduler

    设置和 director 相关联的 cc.Scheduler。

    metadescription
    定义于cocos2d/core/CCDirector.js:816
    参数列表
    • scheduler Scheduler
    getActionManager

    获取和 director 相关联的 cc.ActionManager(动作管理器)。

    metadescription
    返回ActionManager
    定义于cocos2d/core/CCDirector.js:828
    setActionManager

    设置和 director 相关联的 cc.ActionManager(动作管理器)。

    metadescription
    定义于cocos2d/core/CCDirector.js:837
    参数列表
    • actionManager ActionManager
    getCollisionManager

    获取和 director 相关联的 cc.CollisionManager (碰撞管理器)。

    metadescription
    返回CollisionManager
    定义于cocos2d/core/CCDirector.js:863
    getPhysicsManager

    返回与 director 相关联的 cc.PhysicsManager (物理管理器)。

    metadescription
    返回PhysicsManager
    定义于cocos2d/core/CCDirector.js:873
    hasEventListener

    检查事件目标对象是否有为特定类型的事件注册的回调。

    metadescription
    返回Boolean
    定义于cocos2d/core/event/event-target.js:68
    参数列表
    • type String The type of event.
    on

    注册事件目标的特定事件类型回调。这种类型的事件应该被 emit 触发。

    metadescription
    返回Function
    定义于cocos2d/core/event/event-target.js:76
    参数列表
    • type String A string representing the event type to listen for.
    • callback Function The callback that will be invoked when the event is dispatched.
    1. The callback is ignored if it is a duplicate (the callbacks are unique).
    • arg1 Any arg1
    • arg2 Any arg2
    • arg3 Any arg3
    • arg4 Any arg4
    • arg5 Any arg5
      • target Object The target (this object) to invoke the callback, can be null
    示例
    1. eventTarget.on('fire', function () {
    2. cc.log("fire in the hole");
    3. }, node);
    off

    删除之前用同类型,回调,目标或 useCapture 注册的事件监听器,如果只传递 type,将会删除 type 类型的所有事件监听器。

    metadescription
    定义于cocos2d/core/event/event-target.js:116
    参数列表
    • type String A string representing the event type being removed.
    • callback Function The callback to remove.
    • target Object The target (this object) to invoke the callback, if it's not given, only callback without target will be removed
    示例
    1. // register fire eventListener
    2. var callback = eventTarget.on('fire', function () {
    3. cc.log("fire in the hole");
    4. }, target);
    5. // remove fire event listener
    6. eventTarget.off('fire', callback, target);
    7. // remove all fire event listeners
    8. eventTarget.off('fire');
    targetOff

    在当前 EventTarget 上删除指定目标(target 参数)注册的所有事件监听器。这个函数无法删除当前 EventTarget 的所有事件监听器,也无法删除 target 参数所注册的所有事件监听器。这个函数只能删除 target 参数在当前 EventTarget 上注册的所有事件监听器。

    metadescription
    定义于cocos2d/core/event/event-target.js:150
    参数列表
    • target Object The target to be searched for all related listeners
    once

    注册事件目标的特定事件类型回调,回调会在第一时间被触发后删除自身。

    metadescription
    定义于cocos2d/core/event/event-target.js:163
    参数列表
    • type String A string representing the event type to listen for.
    • callback Function The callback that will be invoked when the event is dispatched.
    1. The callback is ignored if it is a duplicate (the callbacks are unique).
    • arg1 Any arg1
    • arg2 Any arg2
    • arg3 Any arg3
    • arg4 Any arg4
    • arg5 Any arg5
      • target Object The target (this object) to invoke the callback, can be null
    示例
    1. eventTarget.once('fire', function () {
    2. cc.log("this is the callback and will be invoked only once");
    3. }, node);
    emit

    通过事件名发送自定义事件

    metadescription
    定义于cocos2d/core/event/event-target.js:200
    参数列表
    • type String event type
    • arg1 Any First argument
    • arg2 Any Second argument
    • arg3 Any Third argument
    • arg4 Any Fourth argument
    • arg5 Any Fifth argument
    示例
    1. eventTarget.emit('fire', event);
    2. eventTarget.emit('fire', message, emitter);
    dispatchEvent

    通过事件对象派发事件

    metadescription
    定义于cocos2d/core/event/event-target.js:220
    参数列表
    • event Event

    事件

    cc.Director.EVENT_BEFORE_SCENE_LOADING Event

    模块: cc

    加载新场景之前所触发的事件。

    索引

    Details

    cc.Director.EVENT_AFTER_SCENE_LAUNCH Event

    模块: cc

    运行新场景之后所触发的事件。

    索引

    Details

    cc.Director.EVENT_BEFORE_UPDATE Event

    模块: cc

    每个帧的开始时所触发的事件。

    索引

    Details

    cc.Director.EVENT_AFTER_UPDATE Event

    模块: cc

    将在引擎和组件 “update” 逻辑之后所触发的事件。

    索引

    Details

    cc.Director.EVENT_BEFORE_DRAW Event

    模块: cc

    渲染过程之前所触发的事件。

    索引

    Details

    cc.Director.EVENT_AFTER_DRAW Event

    模块: cc

    渲染过程之后所触发的事件。

    索引

    Details