RigidBody 类型

继承于 Component

模块: cc 父模块: cc

索引

属性(properties)
  • enabledContactListener Boolean 是否启用接触接听器。
  • bullet Boolean - 所有刚体都被禁止从 运动刚体 和 静态刚体 中穿过。
  • type RigidBodyType 刚体类型: Static, Kinematic, Dynamic or Animated.
  • allowSleep Boolean 如果此刚体永远都不应该进入睡眠,那么设置这个属性为 false。
  • gravityScale Number 缩放应用在此刚体上的重力值
  • linearDamping Number Linear damping 用于衰减刚体的线性速度。
  • angularDamping Number Angular damping 用于衰减刚体的角速度。
  • linearVelocity Vec2 刚体在世界坐标下的线性速度
  • angularVelocity Number 刚体的角速度
  • fixedRotation Boolean 是否禁止此刚体进行旋转
  • awake Boolean 是否立刻唤醒此刚体
  • active Boolean 设置刚体的激活状态。
  • __eventTargets Array Register all related EventTargets,...
  • node Node 该组件被附加到的节点。
  • uuid String 组件的 uuid,用于编辑器。
  • _enabled Boolean
  • enabled Boolean 表示该组件自身是否启用。
  • enabledInHierarchy Boolean 表示该组件是否被启用并且所在的节点也处于激活状态。
  • _isOnLoadCalled Number 返回一个值用来判断 onLoad 是否被调用过,不等于 0 时调用过,等于 0 时未调用。
  • _name String
  • _objFlags Number
  • name String 该对象的名称。
  • isValid Boolean 表示该对象是否可用(被 destroy 后将不可用)。
方法
  • onBeginContact 碰撞回调。
  • onEndContact 碰撞回调。
  • onPreSolve 碰撞回调。
  • onPostSolve 碰撞回调。
  • getLocalPoint 将一个给定的世界坐标系下的点转换为刚体本地坐标系下的点
  • getWorldPoint 将一个给定的刚体本地坐标系下的点转换为世界坐标系下的点
  • getWorldVector 将一个给定的世界坐标系下的向量转换为刚体本地坐标系下的向量
  • getLocalVector 将一个给定的世界坐标系下的点转换为刚体本地坐标系下的点
  • getWorldPosition 获取刚体世界坐标系下的原点值
  • getWorldRotation 获取刚体世界坐标系下的旋转值。
  • getLocalCenter 获取刚体本地坐标系下的质心
  • getWorldCenter 获取刚体世界坐标系下的质心
  • getLinearVelocityFromWorldPoint 获取刚体上指定点的线性速度
  • getMass 获取刚体的质量。
  • getInertia 获取刚体本地坐标系下原点的旋转惯性
  • getJointList 获取链接到此刚体的所有关节
  • applyForce 施加一个力到刚体上的一个点。
  • applyForceToCenter 施加一个力到刚体上的质心上。
  • applyTorque 施加一个扭矩力,将影响刚体的角速度
  • applyLinearImpulse 施加冲量到刚体上的一个点,将立即改变刚体的线性速度。
  • applyAngularImpulse 施加一个角速度冲量。
  • syncPosition 同步节点的世界坐标到 box2d 刚体的坐标上。
  • syncRotation 同步节点的世界旋转角度值到 box2d 刚体的旋转值上。
  • update 如果该组件启用,则每帧调用 update。
  • lateUpdate 如果该组件启用,则每帧调用 LateUpdate。
  • __preload __preload is called before every onLoad....
  • onLoad 当附加到一个激活的节点上或者其节点第一次激活时候调用。
  • start 如果该组件第一次启用,则在所有组件的 update 之前调用。
  • onEnable 当该组件被启用,并且它的节点也激活时。
  • onDisable 当该组件被禁用或节点变为无效时调用。
  • onDestroy 当该组件被销毁时调用
  • onFocusInEditor
  • onLostFocusInEditor
  • resetInEditor 用来初始化组件或节点的一些属性,当该组件被第一次添加到节点上或用户点击了它的 Reset 菜单时调用。
  • addComponent 向节点添加一个组件类,你还可以通过传入脚本的名称来添加组件。
  • getComponent 获取节点上指定类型的组件,如果节点有附加指定类型的组件,则返回,如果没有则为空。
  • getComponents 返回节点上指定类型的所有组件。
  • getComponentInChildren 递归查找所有子节点中第一个匹配指定类型的组件。
  • getComponentsInChildren 递归查找自身或所有子节点中指定类型的组件
  • _getLocalBounds 以便编辑器的场景视图可以正确地执行点选测试。
  • onRestore onRestore 是用户在检查器菜单点击 Reset 时,对此组件执行撤消操作后调用的。
  • schedule 调度一个自定义的回调函数。
  • scheduleOnce 调度一个只运行一次的回调函数,可以指定 0 让回调函数在下一帧立即执行或者在一定的延时之后执行。
  • unschedule 取消调度一个自定义的回调函数。
  • unscheduleAllCallbacks 取消调度所有已调度的回调函数:定制的回调函数以及 'update' 回调函数。
  • destroy 销毁该对象,并释放所有它对其它对象的引用。
  • _destruct Clear all references in the instance....
  • _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)

enabledContactListener

是否启用接触接听器。 当 collider 产生碰撞时,只有开启了接触接听器才会调用相应的回调函数

meta description
类型 Boolean
定义于 cocos2d/core/physics/CCRigidBody.js:76
bullet

这个刚体是否是一个快速移动的刚体,并且需要禁止穿过其他快速移动的刚体? 需要注意的是 :

  • 所有刚体都被禁止从 运动刚体 和 静态刚体 中穿过。此选项只关注于 动态刚体。
  • 应该尽量少的使用此选项,因为它会增加程序处理时间。
meta description
类型 Boolean
定义于 cocos2d/core/physics/CCRigidBody.js:150
type

刚体类型: Static, Kinematic, Dynamic or Animated.

meta description
类型 RigidBodyType
定义于 cocos2d/core/physics/CCRigidBody.js:170
allowSleep

如果此刚体永远都不应该进入睡眠,那么设置这个属性为 false。 需要注意这将使 CPU 占用率提高。

meta description
类型 Boolean
定义于 cocos2d/core/physics/CCRigidBody.js:198
gravityScale

缩放应用在此刚体上的重力值

meta description
类型 Number
定义于 cocos2d/core/physics/CCRigidBody.js:225
linearDamping

Linear damping 用于衰减刚体的线性速度。衰减系数可以大于 1,但是当衰减系数比较大的时候,衰减的效果会变得比较敏感。

meta description
类型 Number
定义于 cocos2d/core/physics/CCRigidBody.js:246
angularDamping

Angular damping 用于衰减刚体的角速度。衰减系数可以大于 1,但是当衰减系数比较大的时候,衰减的效果会变得比较敏感。

meta description
类型 Number
定义于 cocos2d/core/physics/CCRigidBody.js:269
linearVelocity

刚体在世界坐标下的线性速度

meta description
类型 Vec2
定义于 cocos2d/core/physics/CCRigidBody.js:292
angularVelocity

刚体的角速度

meta description
类型 Number
定义于 cocos2d/core/physics/CCRigidBody.js:323
fixedRotation

是否禁止此刚体进行旋转

meta description
类型 Boolean
定义于 cocos2d/core/physics/CCRigidBody.js:347
awake

是否立刻唤醒此刚体

meta description
类型 Boolean
定义于 cocos2d/core/physics/CCRigidBody.js:368
active

设置刚体的激活状态。一个非激活状态下的刚体是不会被模拟和碰撞的,不管它是否处于睡眠状态下。 如果刚体处于激活状态下,所有夹具会被添加到 粗测阶段(broad-phase)。 如果刚体处于非激活状态下,所有夹具会被从 粗测阶段(broad-phase)中移除。 在非激活状态下的夹具不会参与到碰撞,射线,或者查找中 链接到非激活状态下刚体的关节也是非激活的。

meta description
类型 Boolean
定义于 cocos2d/core/physics/CCRigidBody.js:388
__eventTargets

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

meta description
类型 Array
定义于 cocos2d/core/components/CCComponent.js:62
node

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

meta description
类型 Node
定义于 cocos2d/core/components/CCComponent.js:76
示例
cc.log(comp.node);
uuid

组件的 uuid,用于编辑器。

meta description
类型 String
定义于 cocos2d/core/components/CCComponent.js:112
示例
cc.log(comp.uuid);
_enabled
meta description
类型 Boolean
定义于 cocos2d/core/components/CCComponent.js:160
enabled

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

meta description
类型 Boolean
定义于 cocos2d/core/components/CCComponent.js:167
示例
comp.enabled = true;
cc.log(comp.enabled);
enabledInHierarchy

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

meta description
类型 Boolean
定义于 cocos2d/core/components/CCComponent.js:198
示例
cc.log(comp.enabledInHierarchy);
_isOnLoadCalled

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

meta description
类型 Number
定义于 cocos2d/core/components/CCComponent.js:214
示例
cc.log(this._isOnLoadCalled > 0);
_name
meta description
类型 String
定义于 cocos2d/core/platform/CCObject.js:76
_objFlags
meta description
类型 Number
定义于 cocos2d/core/platform/CCObject.js:83
name

该对象的名称。

meta description
类型 String
定义于 cocos2d/core/platform/CCObject.js:243
示例
obj.name = "New Obj";
isValid

表示该对象是否可用(被 destroy 后将不可用)。
当一个对象的 destroy 调用以后,会在这一帧结束后才真正销毁。因此从下一帧开始 isValid 就会返回 false,而当前帧内 isValid 仍然会是 true。如果希望判断当前帧是否调用过 destroy,请使用 cc.isValid(obj, true),不过这往往是特殊的业务需求引起的,通常情况下不需要这样。

meta description
类型 Boolean
定义于 cocos2d/core/platform/CCObject.js:261
示例
var node = new cc.Node();
cc.log(node.isValid);    // true
node.destroy();
cc.log(node.isValid);    // true, still valid in this frame
// after a frame...
cc.log(node.isValid);    // false, destroyed in the end of last frame

方法

onBeginContact

碰撞回调。 如果你的脚本中实现了这个函数,那么它将会在两个碰撞体开始接触时被调用。

meta description
定义于 cocos2d/core/physics/CCRigidBody.js:91
参数列表
onEndContact

碰撞回调。 如果你的脚本中实现了这个函数,那么它将会在两个碰撞体停止接触时被调用。

meta description
定义于 cocos2d/core/physics/CCRigidBody.js:103
参数列表
onPreSolve

碰撞回调。 如果你的脚本中实现了这个函数,那么它将会在接触更新时被调用。 你可以在接触被处理前根据他包含的信息作出相应的处理,比如将这个接触禁用掉。 注意:回调只会为醒着的刚体调用。 注意:接触点为零的时候也有可能被调用。 注意:感知体(sensor)的回调不会被调用。

meta description
定义于 cocos2d/core/physics/CCRigidBody.js:115
参数列表
onPostSolve

碰撞回调。 如果你的脚本中实现了这个函数,那么它将会在接触更新完后被调用。 你可以在这个回调中从接触信息中获取到冲量信息。

meta description
定义于 cocos2d/core/physics/CCRigidBody.js:135
参数列表
getLocalPoint

将一个给定的世界坐标系下的点转换为刚体本地坐标系下的点

meta description
返回 Vec2
定义于 cocos2d/core/physics/CCRigidBody.js:421
参数列表
  • worldPoint Vec2 a point in world coordinates.
  • out Vec2 optional, the receiving point
getWorldPoint

将一个给定的刚体本地坐标系下的点转换为世界坐标系下的点

meta description
返回 Vec2
定义于 cocos2d/core/physics/CCRigidBody.js:442
参数列表
  • localPoint Vec2 a point in local coordinates.
  • out Vec2 optional, the receiving point
getWorldVector

将一个给定的世界坐标系下的向量转换为刚体本地坐标系下的向量

meta description
返回 Vec2
定义于 cocos2d/core/physics/CCRigidBody.js:463
参数列表
  • localVector Vec2 a vector in world coordinates.
  • out Vec2 optional, the receiving vector
getLocalVector

将一个给定的世界坐标系下的点转换为刚体本地坐标系下的点

meta description
返回 Vec2
定义于 cocos2d/core/physics/CCRigidBody.js:484
参数列表
  • worldVector Vec2 a vector in world coordinates.
  • out Vec2 optional, the receiving vector
getWorldPosition

获取刚体世界坐标系下的原点值

meta description
返回 Vec2
定义于 cocos2d/core/physics/CCRigidBody.js:505
参数列表
  • out Vec2 optional, the receiving point
getWorldRotation

获取刚体世界坐标系下的旋转值。

meta description
返回 Number
定义于 cocos2d/core/physics/CCRigidBody.js:524
getLocalCenter

获取刚体本地坐标系下的质心

meta description
返回 Vec2
定义于 cocos2d/core/physics/CCRigidBody.js:539
getWorldCenter

获取刚体世界坐标系下的质心

meta description
返回 Vec2
定义于 cocos2d/core/physics/CCRigidBody.js:557
getLinearVelocityFromWorldPoint

获取刚体上指定点的线性速度

meta description
返回 Vec2
定义于 cocos2d/core/physics/CCRigidBody.js:575
参数列表
  • worldPoint Vec2 a point in world coordinates.
  • out Vec2 optional, the receiving point
getMass

获取刚体的质量。

meta description
返回 Number
定义于 cocos2d/core/physics/CCRigidBody.js:596
getInertia

获取刚体本地坐标系下原点的旋转惯性

meta description
返回 Number
定义于 cocos2d/core/physics/CCRigidBody.js:608
getJointList

获取链接到此刚体的所有关节

meta description
返回 [Joint]
定义于 cocos2d/core/physics/CCRigidBody.js:620
applyForce

施加一个力到刚体上的一个点。如果力没有施加到刚体的质心上,还会产生一个扭矩并且影响到角速度。

meta description
定义于 cocos2d/core/physics/CCRigidBody.js:664
参数列表
  • force Vec2 the world force vector.
  • point Vec2 the world position.
  • wake Boolean also wake up the body.
applyForceToCenter

施加一个力到刚体上的质心上。

meta description
定义于 cocos2d/core/physics/CCRigidBody.js:684
参数列表
  • force Vec2 the world force vector.
  • wake Boolean also wake up the body.
applyTorque

施加一个扭矩力,将影响刚体的角速度

meta description
定义于 cocos2d/core/physics/CCRigidBody.js:700
参数列表
  • torque Number about the z-axis (out of the screen), usually in N-m.
  • wake Boolean also wake up the body
applyLinearImpulse

施加冲量到刚体上的一个点,将立即改变刚体的线性速度。 如果冲量施加到的点不是刚体的质心,那么将产生一个扭矩并影响刚体的角速度。

meta description
定义于 cocos2d/core/physics/CCRigidBody.js:715
参数列表
  • impulse Vec2 the world impulse vector, usually in N-seconds or kg-m/s.
  • point Vec2 the world position
  • wake Boolean alse wake up the body
applyAngularImpulse

施加一个角速度冲量。

meta description
定义于 cocos2d/core/physics/CCRigidBody.js:736
参数列表
  • impulse Number the angular impulse in units of kgmm/s
  • wake Boolean also wake up the body
syncPosition

同步节点的世界坐标到 box2d 刚体的坐标上。 如果 enableAnimated 是 true,并且刚体的类型是 Animated ,那么将设置刚体的线性速度来代替直接设置刚体的位置。

meta description
定义于 cocos2d/core/physics/CCRigidBody.js:751
参数列表
syncRotation

同步节点的世界旋转角度值到 box2d 刚体的旋转值上。 如果 enableAnimated 是 true,并且刚体的类型是 Animated ,那么将设置刚体的角速度来代替直接设置刚体的角度。

meta description
定义于 cocos2d/core/physics/CCRigidBody.js:796
参数列表
update

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

meta description
定义于 cocos2d/core/components/CCComponent.js:235
参数列表
  • dt Number the delta time in seconds it took to complete the last frame
lateUpdate

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

meta description
定义于 cocos2d/core/components/CCComponent.js:244
__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
定义于 cocos2d/core/components/CCComponent.js:252
onLoad

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

meta description
定义于 cocos2d/core/components/CCComponent.js:263
start

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

meta description
定义于 cocos2d/core/components/CCComponent.js:274
onEnable

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

meta description
定义于 cocos2d/core/components/CCComponent.js:285
onDisable

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

meta description
定义于 cocos2d/core/components/CCComponent.js:293
onDestroy

当该组件被销毁时调用

meta description
定义于 cocos2d/core/components/CCComponent.js:301
onFocusInEditor
meta description
定义于 cocos2d/core/components/CCComponent.js:309
onLostFocusInEditor
meta description
定义于 cocos2d/core/components/CCComponent.js:314
resetInEditor

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

meta description
定义于 cocos2d/core/components/CCComponent.js:319
addComponent

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

meta description
返回 Component
定义于 cocos2d/core/components/CCComponent.js:329
参数列表
  • 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
定义于 cocos2d/core/components/CCComponent.js:347
参数列表
示例
// get sprite component.
var sprite = node.getComponent(cc.Sprite);
// get custom test calss.
var test = node.getComponent("Test");
getComponents

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

meta description
返回 Component[]
定义于 cocos2d/core/components/CCComponent.js:371
参数列表
示例
var sprites = node.getComponents(cc.Sprite);
var tests = node.getComponents("Test");
getComponentInChildren

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

meta description
返回 Component
定义于 cocos2d/core/components/CCComponent.js:389
参数列表
示例
var sprite = node.getComponentInChildren(cc.Sprite);
var Test = node.getComponentInChildren("Test");
getComponentsInChildren

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

meta description
返回 Component[]
定义于 cocos2d/core/components/CCComponent.js:407
参数列表
示例
var sprites = node.getComponentsInChildren(cc.Sprite);
var tests = node.getComponentsInChildren("Test");
_getLocalBounds

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

meta description
定义于 cocos2d/core/components/CCComponent.js:427
参数列表
  • out_rect Rect the Rect to receive the bounding box
onRestore

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

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

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

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

meta description
定义于 cocos2d/core/components/CCComponent.js:440
schedule

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

meta description
定义于 cocos2d/core/components/CCComponent.js:542
参数列表
  • 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
定义于 cocos2d/core/components/CCComponent.js:579
参数列表
  • 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
定义于 cocos2d/core/components/CCComponent.js:596
参数列表
  • callback_fn function A function wrapped as a selector
示例
this.unschedule(_callback);
unscheduleAllCallbacks

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

meta description
定义于 cocos2d/core/components/CCComponent.js:612
示例
this.unscheduleAllCallbacks();
destroy

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

meta description
返回 Boolean
定义于 cocos2d/core/platform/CCObject.js:296
示例
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
定义于 cocos2d/core/platform/CCObject.js:428
_onPreDestroy

Called before the object being destroyed.

meta description
定义于 cocos2d/core/platform/CCObject.js:461
_serialize

The customized serialization for this object. (Editor Only)

meta description
返回 object
定义于 cocos2d/core/platform/CCObject.js:486
参数列表
_deserialize

Init this object from the custom serialized data.

meta description
定义于 cocos2d/core/platform/CCObject.js:496
参数列表
  • data Object the serialized json data
  • ctx _Deserializer

results matching ""

    No results matching ""