ParticleSystem 类型

继承于 _RendererUnderSG

模块: cc

Particle System base class.
Attributes of a Particle System:

  • emmision rate of the particles
  • Gravity Mode (Mode A):
  • gravity
  • direction
  • speed +- variance
  • tangential acceleration +- variance
  • radial acceleration +- variance
  • Radius Mode (Mode B):
  • startRadius +- variance
  • endRadius +- variance
  • rotate +- variance
  • Properties common to all modes:
  • life +- life variance
  • start spin +- variance
  • end spin +- variance
  • start size +- variance
  • end size +- variance
  • start color +- variance
  • end color +- variance
  • life +- variance
  • blending function
  • texture

    cocos2d also supports particles generated by Particle Designer (http://particledesigner.71squared.com/).
    'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guarateed in cocos2d,
    cocos2d uses a another approach, but the results are almost identical.
    cocos2d supports all the variables used by Particle Designer plus a bit more:
  • spinning particles (supported when using ParticleSystem)
  • tangential acceleration (Gravity mode)
  • radial acceleration (Gravity mode)
  • radius direction (Radius mode) (Particle Designer supports outwards to inwards direction only)
    It is possible to customize any of the above mentioned properties in runtime. Example:

索引

属性(properties)
  • preview Boolean 在编辑器模式下预览粒子,启用后选中粒子时,粒子将自动播放。
  • custom Boolean 是否自定义粒子属性。
  • file string plist 格式的粒子配置文件。
  • texture Texture2D .
  • particleCount Number 当前播放的粒子数量。
  • srcBlendFactor BlendFactor 指定原图混合模式。
  • dstBlendFactor BlendFactor 指定目标的混合模式。
  • playOnLoad Boolean 如果设置为 true 运行时会自动发射粒子。
  • autoRemoveOnFinish Boolean 粒子播放完毕后自动销毁所在的节点。
  • active Boolean 是否激活粒子。
  • totalParticles Number 粒子最大数量。
  • duration Number 发射器生存时间,单位秒,-1表示持续发射。
  • emissionRate Number 每秒发射的粒子数目。
  • life Number 粒子的运行时间。
  • lifeVar Number 粒子的运行时间变化范围。
  • startColor Color 粒子初始颜色。
  • startColorVar Color 粒子初始颜色变化范围。
  • endColor Color 粒子结束颜色。
  • endColorVar Color 粒子结束颜色变化范围。
  • angle Number 粒子角度。
  • angleVar Number 粒子角度变化范围。
  • startSize Number 粒子的初始大小。
  • startSizeVar Number 粒子初始大小的变化范围。
  • endSize Number 粒子结束时的大小。
  • endSizeVar Number 粒子结束大小的变化范围。
  • startSpin Number 粒子开始自旋角度。
  • startSpinVar Number 粒子开始自旋角度变化范围。
  • endSpin Number 粒子结束自旋角度。
  • endSpinVar Number 粒子结束自旋角度变化范围。
  • sourcePos Vec2 发射器位置。
  • posVar Vec2 发射器位置的变化范围。(横向和纵向)
  • positionType ParticleSystem.PositionType 粒子位置类型。
  • emitterMode ParticleSystem.EmitterMode 发射器类型。
  • gravity Vec2 重力。
  • speed Number 速度。
  • speedVar Number 速度变化范围。
  • tangentialAccel Number 每个粒子的切向加速度,即垂直于重力方向的加速度,只有在重力模式下可用。
  • tangentialAccelVar Number 每个粒子的切向加速度变化范围。
  • radialAccel Number 粒子径向加速度,即平行于重力方向的加速度,只有在重力模式下可用。
  • radialAccelVar Number 粒子径向加速度变化范围。
  • rotationIsDir Boolean 每个粒子的旋转是否等于其方向,只有在重力模式下可用。
  • startRadius Number 初始半径,表示粒子出生时相对发射器的距离,只有在半径模式下可用。
  • startRadiusVar Number 初始半径变化范围。
  • endRadius Number 结束半径,只有在半径模式下可用。
  • endRadiusVar Number 结束半径变化范围。
  • rotatePerS Number 粒子每秒围绕起始点的旋转角度,只有在半径模式下可用。
  • rotatePerSVar Number 粒子每秒围绕起始点的旋转角度变化范围。
  • DURATION_INFINITY Number 表示发射器永久存在
  • START_SIZE_EQUAL_TO_END_SIZE Number 表示粒子的起始大小等于结束大小。
  • START_RADIUS_EQUAL_TO_END_RADIUS Number 表示粒子的起始半径等于结束半径。
  • _sgNode _ccsg.Node Reference to the instance of _ccsg.Node If it is possible to return null from your overloaded _createSgNode, then you should always check for null before using this property and reimplement __preload.
  • __eventTargets Array Register all related EventTargets, all event callbacks will be removed in _onPreDestroy
  • node Node 该组件被附加到的节点。组件总会附加到一个节点。
  • uuid String 组件的 uuid,用于编辑器。
  • _enabled Boolean
  • enabled Boolean 表示该组件自身是否启用。
  • enabledInHierarchy Boolean 表示该组件是否被启用并且所在的节点也处于激活状态。
  • _isOnLoadCalled Number 返回一个值用来判断 onLoad 是否被调用过,不等于 0 时调用过,等于 0 时未调用。
  • _name String
  • _objFlags Number
  • name String 该对象的名称。
  • isValid Boolean 表示该对象是否可用(被销毁后将不可用)。
方法
  • addParticle 添加一个粒子到发射器中。
  • stopSystem 停止发射器发射粒子,发射出去的粒子将继续运行,直至粒子生命结束。
  • resetSystem 杀死所有存在的粒子,然后重新启动粒子发射器。
  • isFull 发射器中粒子是否大于等于设置的总粒子数量。
  • setDisplayFrame

    设置一个新的精灵帧为粒子。
    警告:这个函数只是试验,请使用 setTextureWithRect 实现。

  • setTextureWithRect 设置一张新贴图和关联的矩形。
  • _createSgNode Create and returns your new scene graph node (SGNode) to add to scene graph. You should call the setContentSize of the SGNode if its size should be the same with the node's.
  • _initSgNode
  • _removeSgNode
  • update 如果该组件启用,则每帧调用 update。
  • lateUpdate 如果该组件启用,则每帧调用 LateUpdate。
  • __preload __preload is called before every onLoad. It is used to initialize the builtin components internally, to avoid checking whether onLoad is called before every public method calls. This method should be removed if script priority is supported.
  • onLoad 当附加到一个激活的节点上或者其节点第一次激活时候调用。onLoad 总是会在任何 start 方法调用前执行,这能用于安排脚本的初始化顺序。
  • start 如果该组件第一次启用,则在所有组件的 update 之前调用。通常用于需要在所有组件的 onLoad 初始化完毕后执行的逻辑。
  • onEnable 当该组件被启用,并且它的节点也激活时。
  • onDisable 当该组件被禁用或节点变为无效时调用。
  • onDestroy 当该组件被销毁时调用
  • onFocusInEditor
  • onLostFocusInEditor
  • resetInEditor 用来初始化组件或节点的一些属性,当该组件被第一次添加到节点上或用户点击了它的 Reset 菜单时调用。这个回调只会在编辑器下调用。
  • addComponent 向节点添加一个组件类,你还可以通过传入脚本的名称来添加组件。
  • getComponent 获取节点上指定类型的组件,如果节点有附加指定类型的组件,则返回,如果没有则为空。
    传入参数也可以是脚本的名称。
  • getComponents 返回节点上指定类型的所有组件。
  • getComponentInChildren 递归查找所有子节点中第一个匹配指定类型的组件。
  • getComponentsInChildren 递归查找自身或所有子节点中指定类型的组件
  • _getLocalBounds 如果组件的包围盒与节点不同,您可以实现该方法以提供自定义的轴向对齐的包围盒(AABB), 以便编辑器的场景视图可以正确地执行点选测试。
  • onRestore onRestore 是用户在检查器菜单点击 Reset 时,对此组件执行撤消操作后调用的。

    如果组件包含了“内部状态”(不在 CCClass 属性中定义的临时成员变量),那么你可能需要实现该方法。

    编辑器执行撤销/重做操作时,将调用组件的 get set 来录制和还原组件的状态。 然而,在极端的情况下,它可能无法良好运作。
    那么你就应该实现这个方法,手动根据组件的属性同步“内部状态”。 一旦你实现这个方法,当用户撤销或重做时,组件的所有 get set 都不会再被调用。 这意味着仅仅指定了默认值的属性将被编辑器记录和还原。

    同样的,编辑可能无法在极端情况下正确地重置您的组件。
    于是如果你需要支持组件重置菜单,你需要在该方法中手工同步组件属性到“内部状态”。
    一旦你实现这个方法,组件的所有 get set 都不会在重置操作时被调用。 这意味着仅仅指定了默认值的属性将被编辑器重置。
    此方法仅在编辑器下会被调用。
  • schedule 调度一个自定义的回调函数。
    如果回调函数已调度,那么将不会重复调度它,只会更新时间间隔参数。
  • scheduleOnce 调度一个只运行一次的回调函数,可以指定 0 让回调函数在下一帧立即执行或者在一定的延时之后执行。
  • unschedule 取消调度一个自定义的回调函数。
  • unscheduleAllCallbacks 取消调度所有已调度的回调函数:定制的回调函数以及 'update' 回调函数。动作不受此方法影响。
  • destroy 销毁该对象,并释放所有它对其它对象的引用。
    销毁后,CCObject 不再可用。您可以在访问对象之前使用 cc.isValid(obj) 来检查对象是否已被销毁。 实际销毁操作会延迟到当前帧渲染前执行。
  • _destruct Clear all references in the instance.

NOTE: this method will not clear the getter or setter functions which defined in the instance of CCObject. You can override the _destruct method if you need, for example: _destruct: function () { for (var key in this) { if (this.hasOwnProperty(key)) { switch (typeof this[key]) { case 'string': this[key] = ''; break; case 'object': case 'function': this[key] = null; break; } } }

  • _onPreDestroy Called before the object being destroyed.
  • _serialize The customized serialization for this object. (Editor Only)
  • _deserialize Init this object from the custom serialized data.

Details

属性(properties)

preview

在编辑器模式下预览粒子,启用后选中粒子时,粒子将自动播放。

meta description
类型 Boolean
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:96
custom

是否自定义粒子属性。

meta description
类型 Boolean
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:116
file

plist 格式的粒子配置文件。

meta description
类型 string
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:150
texture

.

meta description
类型 Texture2D
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:184
particleCount

当前播放的粒子数量。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:209
srcBlendFactor

指定原图混合模式。

meta description
类型 BlendFactor
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:225
dstBlendFactor

指定目标的混合模式。

meta description
类型 BlendFactor
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:246
playOnLoad

如果设置为 true 运行时会自动发射粒子。

meta description
类型 Boolean
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:267
autoRemoveOnFinish

粒子播放完毕后自动销毁所在的节点。

meta description
类型 Boolean
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:276
active

是否激活粒子。

meta description
类型 Boolean
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:298
totalParticles

粒子最大数量。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:314
duration

发射器生存时间,单位秒,-1表示持续发射。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:321
emissionRate

每秒发射的粒子数目。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:328
life

粒子的运行时间。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:335
lifeVar

粒子的运行时间变化范围。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:342
startColor

粒子初始颜色。

meta description
类型 Color
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:350
startColorVar

粒子初始颜色变化范围。

meta description
类型 Color
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:357
endColor

粒子结束颜色。

meta description
类型 Color
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:364
endColorVar

粒子结束颜色变化范围。

meta description
类型 Color
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:371
angle

粒子角度。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:379
angleVar

粒子角度变化范围。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:386
startSize

粒子的初始大小。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:393
startSizeVar

粒子初始大小的变化范围。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:400
endSize

粒子结束时的大小。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:407
endSizeVar

粒子结束大小的变化范围。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:414
startSpin

粒子开始自旋角度。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:421
startSpinVar

粒子开始自旋角度变化范围。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:428
endSpin

粒子结束自旋角度。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:435
endSpinVar

粒子结束自旋角度变化范围。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:442
sourcePos

发射器位置。

meta description
类型 Vec2
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:450
posVar

发射器位置的变化范围。(横向和纵向)

meta description
类型 Vec2
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:458
positionType

粒子位置类型。

meta description
类型 ParticleSystem.PositionType
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:466
emitterMode

发射器类型。

meta description
类型 ParticleSystem.EmitterMode
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:473
gravity

重力。

meta description
类型 Vec2
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:483
speed

速度。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:490
speedVar

速度变化范围。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:497
tangentialAccel

每个粒子的切向加速度,即垂直于重力方向的加速度,只有在重力模式下可用。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:504
tangentialAccelVar

每个粒子的切向加速度变化范围。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:511
radialAccel

粒子径向加速度,即平行于重力方向的加速度,只有在重力模式下可用。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:518
radialAccelVar

粒子径向加速度变化范围。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:525
rotationIsDir

每个粒子的旋转是否等于其方向,只有在重力模式下可用。

meta description
类型 Boolean
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:533
startRadius

初始半径,表示粒子出生时相对发射器的距离,只有在半径模式下可用。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:543
startRadiusVar

初始半径变化范围。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:550
endRadius

结束半径,只有在半径模式下可用。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:557
endRadiusVar

结束半径变化范围。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:564
rotatePerS

粒子每秒围绕起始点的旋转角度,只有在半径模式下可用。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:571
rotatePerSVar

粒子每秒围绕起始点的旋转角度变化范围。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:578
DURATION_INFINITY

表示发射器永久存在

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:705
START_SIZE_EQUAL_TO_END_SIZE

表示粒子的起始大小等于结束大小。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:715
START_RADIUS_EQUAL_TO_END_RADIUS

表示粒子的起始半径等于结束半径。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:725
_sgNode

Reference to the instance of _ccsg.Node If it is possible to return null from your overloaded _createSgNode, then you should always check for null before using this property and reimplement __preload.

meta description
类型 _ccsg.Node
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCRendererUnderSG.js:41
__eventTargets

Register all related EventTargets, all event callbacks will be removed in _onPreDestroy

meta description
类型 Array
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:61
node

该组件被附加到的节点。组件总会附加到一个节点。

meta description
类型 Node
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:75
示例
cc.log(comp.node);
uuid

组件的 uuid,用于编辑器。

meta description
类型 String
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:111
示例
cc.log(comp.uuid);
_enabled
meta description
类型 Boolean
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:159
enabled

表示该组件自身是否启用。

meta description
类型 Boolean
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:166
示例
comp.enabled = true;
cc.log(comp.enabled);
enabledInHierarchy

表示该组件是否被启用并且所在的节点也处于激活状态。

meta description
类型 Boolean
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:197
示例
cc.log(comp.enabledInHierarchy);
_isOnLoadCalled

返回一个值用来判断 onLoad 是否被调用过,不等于 0 时调用过,等于 0 时未调用。

meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:213
示例
cc.log(this._isOnLoadCalled > 0);
_name
meta description
类型 String
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:50
_objFlags
meta description
类型 Number
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:57
name

该对象的名称。

meta description
类型 String
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:208
示例
obj.name = "New Obj";
isValid

表示该对象是否可用(被销毁后将不可用)。

meta description
类型 Boolean
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:225
示例
cc.log(obj.isValid);

方法

addParticle

添加一个粒子到发射器中。

meta description
返回 Boolean
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:826
stopSystem

停止发射器发射粒子,发射出去的粒子将继续运行,直至粒子生命结束。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:836
示例
// stop particle system.
myParticleSystem.stopSystem();
resetSystem

杀死所有存在的粒子,然后重新启动粒子发射器。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:848
示例
// play particle system.
myParticleSystem.resetSystem();
isFull

发射器中粒子是否大于等于设置的总粒子数量。

meta description
返回 Boolean
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:860
setDisplayFrame

设置一个新的精灵帧为粒子。
警告:这个函数只是试验,请使用 setTextureWithRect 实现。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:870
参数列表
setTextureWithRect

设置一张新贴图和关联的矩形。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/particle/CCParticleSystem.js:893
参数列表
_createSgNode

Create and returns your new scene graph node (SGNode) to add to scene graph. You should call the setContentSize of the SGNode if its size should be the same with the node's.

meta description
返回 _ccsg.Node
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCSGComponent.js:65
_initSgNode
meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCSGComponent.js:75
_removeSgNode
meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCSGComponent.js:81
update

如果该组件启用,则每帧调用 update。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:234
参数列表
  • dt Number the delta time in seconds it took to complete the last frame
lateUpdate

如果该组件启用,则每帧调用 LateUpdate。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:243
__preload

__preload is called before every onLoad. It is used to initialize the builtin components internally, to avoid checking whether onLoad is called before every public method calls. This method should be removed if script priority is supported.

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:251
onLoad

当附加到一个激活的节点上或者其节点第一次激活时候调用。onLoad 总是会在任何 start 方法调用前执行,这能用于安排脚本的初始化顺序。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:262
start

如果该组件第一次启用,则在所有组件的 update 之前调用。通常用于需要在所有组件的 onLoad 初始化完毕后执行的逻辑。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:273
onEnable

当该组件被启用,并且它的节点也激活时。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:284
onDisable

当该组件被禁用或节点变为无效时调用。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:292
onDestroy

当该组件被销毁时调用

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:300
onFocusInEditor
meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:308
onLostFocusInEditor
meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:313
resetInEditor

用来初始化组件或节点的一些属性,当该组件被第一次添加到节点上或用户点击了它的 Reset 菜单时调用。这个回调只会在编辑器下调用。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:318
addComponent

向节点添加一个组件类,你还可以通过传入脚本的名称来添加组件。

meta description
返回 Component
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:328
参数列表
  • typeOrClassName Function | String the constructor or the class name of the component to add
示例
var sprite = node.addComponent(cc.Sprite);
var test = node.addComponent("Test");
getComponent

获取节点上指定类型的组件,如果节点有附加指定类型的组件,则返回,如果没有则为空。
传入参数也可以是脚本的名称。

meta description
返回 Component
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:346
参数列表
示例
// get sprite component.
var sprite = node.getComponent(cc.Sprite);
// get custom test calss.
var test = node.getComponent("Test");
getComponents

返回节点上指定类型的所有组件。

meta description
返回 Component[]
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:370
参数列表
示例
var sprites = node.getComponents(cc.Sprite);
var tests = node.getComponents("Test");
getComponentInChildren

递归查找所有子节点中第一个匹配指定类型的组件。

meta description
返回 Component
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:388
参数列表
示例
var sprite = node.getComponentInChildren(cc.Sprite);
var Test = node.getComponentInChildren("Test");
getComponentsInChildren

递归查找自身或所有子节点中指定类型的组件

meta description
返回 Component[]
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:406
参数列表
示例
var sprites = node.getComponentsInChildren(cc.Sprite);
var tests = node.getComponentsInChildren("Test");
_getLocalBounds

如果组件的包围盒与节点不同,您可以实现该方法以提供自定义的轴向对齐的包围盒(AABB), 以便编辑器的场景视图可以正确地执行点选测试。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:426
参数列表
  • out_rect Rect the Rect to receive the bounding box
onRestore

onRestore 是用户在检查器菜单点击 Reset 时,对此组件执行撤消操作后调用的。

如果组件包含了“内部状态”(不在 CCClass 属性中定义的临时成员变量),那么你可能需要实现该方法。

编辑器执行撤销/重做操作时,将调用组件的 get set 来录制和还原组件的状态。 然而,在极端的情况下,它可能无法良好运作。
那么你就应该实现这个方法,手动根据组件的属性同步“内部状态”。 一旦你实现这个方法,当用户撤销或重做时,组件的所有 get set 都不会再被调用。 这意味着仅仅指定了默认值的属性将被编辑器记录和还原。

同样的,编辑可能无法在极端情况下正确地重置您的组件。
于是如果你需要支持组件重置菜单,你需要在该方法中手工同步组件属性到“内部状态”。
一旦你实现这个方法,组件的所有 get set 都不会在重置操作时被调用。 这意味着仅仅指定了默认值的属性将被编辑器重置。
此方法仅在编辑器下会被调用。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:439
schedule

调度一个自定义的回调函数。
如果回调函数已调度,那么将不会重复调度它,只会更新时间间隔参数。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:541
参数列表
  • callback function The callback function
  • interval Number Tick interval in seconds. 0 means tick every frame.
  • repeat Number The selector will be executed (repeat + 1) times, you can use cc.macro.REPEAT_FOREVER for tick infinitely.
  • delay Number The amount of time that the first tick will wait before execution.
示例
var timeCallback = function (dt) {
  cc.log("time: " + dt);
}
this.schedule(timeCallback, 1);
scheduleOnce

调度一个只运行一次的回调函数,可以指定 0 让回调函数在下一帧立即执行或者在一定的延时之后执行。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:578
参数列表
  • callback function A function wrapped as a selector
  • delay Number The amount of time that the first tick will wait before execution.
示例
var timeCallback = function (dt) {
  cc.log("time: " + dt);
}
this.scheduleOnce(timeCallback, 2);
unschedule

取消调度一个自定义的回调函数。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:595
参数列表
  • callback_fn function A function wrapped as a selector
示例
this.unschedule(_callback);
unscheduleAllCallbacks

取消调度所有已调度的回调函数:定制的回调函数以及 'update' 回调函数。动作不受此方法影响。

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/components/CCComponent.js:611
示例
this.unscheduleAllCallbacks();
destroy

销毁该对象,并释放所有它对其它对象的引用。
销毁后,CCObject 不再可用。您可以在访问对象之前使用 cc.isValid(obj) 来检查对象是否已被销毁。 实际销毁操作会延迟到当前帧渲染前执行。

meta description
返回 Boolean
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:246
示例
obj.destroy();
_destruct

Clear all references in the instance.

NOTE: this method will not clear the getter or setter functions which defined in the instance of CCObject. You can override the _destruct method if you need, for example: _destruct: function () { for (var key in this) { if (this.hasOwnProperty(key)) { switch (typeof this[key]) { case 'string': this[key] = ''; break; case 'object': case 'function': this[key] = null; break; } } }

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:379
_onPreDestroy

Called before the object being destroyed.

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:412
_serialize

The customized serialization for this object. (Editor Only)

meta description
返回 object
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:437
参数列表
_deserialize

Init this object from the custom serialized data.

meta description
定义于 https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/CCObject.js:447
参数列表
  • data Object the serialized json data
  • ctx _Deserializer

results matching ""

    No results matching ""