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)
方法
  • 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 通过事件对象派发事件
事件

Details

属性(properties)

EVENT_PROJECTION_CHANGED

cc.Director 投影变化的事件。从 v2.0 开始这个事件不会再被触发

meta description
类型 String
定义于 cocos2d/core/CCDirector.js:981
废弃(Deprecated) since v2.0
EVENT_BEFORE_SCENE_LOADING

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

meta description
类型 String
定义于 cocos2d/core/CCDirector.js:997
EVENT_BEFORE_SCENE_LAUNCH

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

meta description
类型 String
定义于 cocos2d/core/CCDirector.js:1012
EVENT_AFTER_SCENE_LAUNCH

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

meta description
类型 String
定义于 cocos2d/core/CCDirector.js:1027
EVENT_BEFORE_UPDATE

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

meta description
类型 String
定义于 cocos2d/core/CCDirector.js:1041
EVENT_AFTER_UPDATE

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

meta description
类型 String
定义于 cocos2d/core/CCDirector.js:1055
EVENT_BEFORE_VISIT

这个事件从 v2.0 开始被废弃,请直接使用 cc.Director.EVENT_BEFORE_DRAW

meta description
类型 String
定义于 cocos2d/core/CCDirector.js:1064
废弃(Deprecated) since v2.0
EVENT_AFTER_VISIT

这个事件从 v2.0 开始被废弃,请直接使用 cc.Director.EVENT_BEFORE_DRAW

meta description
类型 String
定义于 cocos2d/core/CCDirector.js:1074
废弃(Deprecated) since v2.0
EVENT_BEFORE_DRAW

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

meta description
类型 String
定义于 cocos2d/core/CCDirector.js:1089
EVENT_AFTER_DRAW

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

meta description
类型 String
定义于 cocos2d/core/CCDirector.js:1103
PROJECTION_2D

Constant for 2D projection (orthogonal projection)

meta description
类型 Number
定义于 cocos2d/core/CCDirector.js:1114
废弃(Deprecated) since v2.0
PROJECTION_3D

Constant for 3D projection with a fovy=60, znear=0.5f and zfar=1500.

meta description
类型 Number
定义于 cocos2d/core/CCDirector.js:1124
废弃(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.

meta description
类型 Number
定义于 cocos2d/core/CCDirector.js:1134
废弃(Deprecated) since v2.0
PROJECTION_DEFAULT

Constant for default projection of cc.Director, default projection is 2D projection

meta description
类型 Number
定义于 cocos2d/core/CCDirector.js:1144
废弃(Deprecated) since v2.0

方法

convertToGL

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

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

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

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

End the life of director in the next frame

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

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

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

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

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

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

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

立刻切换指定场景。

meta description
定义于 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

运行指定场景。

meta description
定义于 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

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

meta description
返回 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,加载完成后场景就会启动。

meta description
定义于 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.
    • asset cc.SceneAsset The scene asset itself.
_loadSceneByUuid

Loads the scene by its uuid.

meta description
定义于 cocos2d/core/CCDirector.js:614
参数列表
  • 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,
                                only take effect in the Editor.
    
resume

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

meta description
定义于 cocos2d/core/CCDirector.js:677
setDepthTest

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

meta description
定义于 cocos2d/core/CCDirector.js:696
废弃(Deprecated) since v2.0
参数列表
setClearColor

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

meta description
定义于 cocos2d/core/CCDirector.js:712
废弃(Deprecated) since v2.0
参数列表
getRunningScene

获取当前逻辑场景。

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

获取当前逻辑场景。

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

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

meta description
返回 Number
定义于 cocos2d/core/CCDirector.js:755
废弃(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

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

获取上一帧的增量时间。

meta description
返回 Number
定义于 cocos2d/core/CCDirector.js:777
getTotalFrames

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

meta description
返回 Number
定义于 cocos2d/core/CCDirector.js:787
isPaused

是否处于暂停状态。

meta description
返回 Boolean
定义于 cocos2d/core/CCDirector.js:797
getScheduler

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

meta description
返回 Scheduler
定义于 cocos2d/core/CCDirector.js:807
setScheduler

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

meta description
定义于 cocos2d/core/CCDirector.js:817
参数列表
getActionManager

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

meta description
返回 ActionManager
定义于 cocos2d/core/CCDirector.js:829
setActionManager

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

meta description
定义于 cocos2d/core/CCDirector.js:838
参数列表
getCollisionManager

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

meta description
返回 CollisionManager
定义于 cocos2d/core/CCDirector.js:864
getPhysicsManager

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

meta description
返回 PhysicsManager
定义于 cocos2d/core/CCDirector.js:874
hasEventListener

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

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

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

meta description
返回 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.
                           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
示例
eventTarget.on('fire', function () {
    cc.log("fire in the hole");
}, node);
off

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

meta description
定义于 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
示例
// register fire eventListener
var callback = eventTarget.on('fire', function () {
    cc.log("fire in the hole");
}, target);
// remove fire event listener
eventTarget.off('fire', callback, target);
// remove all fire event listeners
eventTarget.off('fire');
targetOff

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

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

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

meta description
定义于 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.
                           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
示例
eventTarget.once('fire', function () {
    cc.log("this is the callback and will be invoked only once");
}, node);
emit

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

meta description
定义于 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
示例
eventTarget.emit('fire', event);
eventTarget.emit('fire', message, emitter);
dispatchEvent

通过事件对象派发事件

meta description
定义于 cocos2d/core/event/event-target.js:220
参数列表

事件

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

条与 "" 相匹配的结果

    没有与 "" 匹配的结果