PageView 类型
继承于 ScrollView
模块: cc
页面视图组件
索引
属性(properties)
sizeModePageView.SizeMode页面视图中每个页面大小类型directionPageView.Direction页面视图滚动类型scrollThresholdNumber滚动临界值,默认单位百分比,当拖拽超出该数值时,松开会自动滚动下一页,小于时则还原。autoPageTurningThresholdNumber快速滑动翻页临界值。pageTurningEventTimingNumber设置 PageView PageTurning 事件的发送时机。indicatorPageViewIndicator页面视图指示器组件pageTurningSpeedNumber每个页面翻页时所需时间。pageEventsComponent.EventHandler[]滚动视图的事件回调函数contentNode可滚动展示内容的节点。horizontalBoolean是否开启水平滚动。verticalBoolean是否开启垂直滚动。inertiaBoolean是否开启滚动惯性。brakeNumber开启惯性后,在用户停止触摸后滚动多快停止,0表示永不停止,1表示立刻停止。elasticBoolean是否允许滚动内容超过边界,并在停止触摸后回弹。bounceDurationNumber回弹持续的时间,0 表示将立即反弹。horizontalScrollBarScrollbar水平滚动的 ScrollBar。verticalScrollBarScrollbar垂直滚动的 ScrollBar。scrollEventsComponent.EventHandler[]滚动视图的事件回调函数cancelInnerEventsBoolean如果这个属性被设置为 true,那么滚动行为会取消子节点上注册的触摸事件,默认被设置为 true。__eventTargetsArray注册所有相关的 EventTargets,所有事件回调将在_onPreDestroy中删除。nodeNode该组件被附加到的节点。uuidString组件的 uuid,用于编辑器。_enabledBooleanenabledBoolean表示该组件自身是否启用。enabledInHierarchyBoolean表示该组件是否被启用并且所在的节点也处于激活状态。_isOnLoadCalledNumber返回一个值用来判断 onLoad 是否被调用过,不等于 0 时调用过,等于 0 时未调用。_nameString_objFlagsNumbernameString该对象的名称。isValidBoolean表示该对象是否可用(被 destroy 后将不可用)。
方法
getCurrentPageIndex返回当前页面索引setCurrentPageIndex设置当前页面索引getPages返回视图中的所有页面addPage在当前页面视图的尾部插入一个新视图insertPage将页面插入指定位置中removePage移除指定页面removePageAtIndex移除指定下标的页面removeAllPages移除所有页面scrollToPage滚动到指定页面scrollToBottom视图内容将在规定时间内滚动到视图底部。scrollToTop视图内容将在规定时间内滚动到视图顶部。scrollToLeft视图内容将在规定时间内滚动到视图左边。scrollToRight视图内容将在规定时间内滚动到视图右边。scrollToTopLeft视图内容将在规定时间内滚动到视图左上角。scrollToTopRight视图内容将在规定时间内滚动到视图右上角。scrollToBottomLeft视图内容将在规定时间内滚动到视图左下角。scrollToBottomRight视图内容将在规定时间内滚动到视图右下角。scrollToOffset视图内容在规定时间内将滚动到 ScrollView 相对左上角原点的偏移位置, 如果 timeInSecond参数不传,则立即滚动到指定偏移位置。getScrollOffset获取滚动视图相对于左上角原点的当前滚动偏移getMaxScrollOffset获取滚动视图最大可以滚动的偏移量scrollToPercentHorizontal视图内容在规定时间内将滚动到 ScrollView 水平方向的百分比位置上。scrollTo视图内容在规定时间内进行垂直方向和水平方向的滚动,并且滚动到指定百分比位置上。scrollToPercentVertical视图内容在规定时间内滚动到 ScrollView 垂直方向的百分比位置上。stopAutoScroll停止自动滚动, 调用此 API 可以让 Scrollview 立即停止滚动setContentPosition设置当前视图内容的坐标点。getContentPosition获取当前视图内容的坐标点。isScrolling用户是否在拖拽当前滚动视图isAutoScrolling当前滚动视图是否在惯性滚动hasNestedViewGroup此 Scoll View 是否含有嵌套的 View Groupupdate如果该组件启用,则每帧调用 update。lateUpdate如果该组件启用,则每帧调用 LateUpdate。__preload__preloadis called before every onLoad....onLoad当附加到一个激活的节点上或者其节点第一次激活时候调用。start如果该组件第一次启用,则在所有组件的 update 之前调用。onEnable当该组件被启用,并且它的节点也激活时。onDisable当该组件被禁用或节点变为无效时调用。onDestroy该方法为生命周期方法,父类未必会有实现。onFocusInEditoronLostFocusInEditorresetInEditor用来初始化组件或节点的一些属性,当该组件被第一次添加到节点上或用户点击了它的 Reset 菜单时调用。addComponent向节点添加一个组件类,你还可以通过传入脚本的名称来添加组件。getComponent获取节点上指定类型的组件,如果节点有附加指定类型的组件,则返回,如果没有则为空。getComponents返回节点上指定类型的所有组件。getComponentInChildren递归查找所有子节点中第一个匹配指定类型的组件。getComponentsInChildren递归查找自身或所有子节点中指定类型的组件_getLocalBounds以便编辑器的场景视图可以正确地执行点选测试。onRestoreonRestore 是用户在检查器菜单点击 Reset 时,对此组件执行撤消操作后调用的。schedule调度一个自定义的回调函数。scheduleOnce调度一个只运行一次的回调函数,可以指定 0 让回调函数在下一帧立即执行或者在一定的延时之后执行。unschedule取消调度一个自定义的回调函数。unscheduleAllCallbacks取消调度所有已调度的回调函数:定制的回调函数以及update回调函数。destroy销毁该对象,并释放所有它对其它对象的引用。_destruct清除实例中的所有引用。_onPreDestroy在对象被销毁之前调用。_serialize为此对象定制序列化。_deserialize从自定义序列化数据初始化此对象。
事件
page-turning注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。scroll-to-top注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。scroll-to-bottom注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。scroll-to-left注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。scroll-to-right注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。scrolling注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。bounce-bottom注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。bounce-top注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。bounce-left注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。bounce-right注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。scroll-ended注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。touch-up注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。scroll-began注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
Details
属性(properties)
sizeMode
页面视图中每个页面大小类型
| meta | description |
|---|---|
| 类型 | PageView.SizeMode |
| 定义于 | cocos2d/core/components/CCPageView.js:113 |
direction
页面视图滚动类型
| meta | description |
|---|---|
| 类型 | PageView.Direction |
| 定义于 | cocos2d/core/components/CCPageView.js:127 |
scrollThreshold
滚动临界值,默认单位百分比,当拖拽超出该数值时,松开会自动滚动下一页,小于时则还原。
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/components/CCPageView.js:141 |
autoPageTurningThreshold
快速滑动翻页临界值。 当用户快速滑动时,会根据滑动开始和结束的距离与时间计算出一个速度值, 该值与此临界值相比较,如果大于临界值,则进行自动翻页。
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/components/CCPageView.js:156 |
pageTurningEventTiming
设置 PageView PageTurning 事件的发送时机。
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/components/CCPageView.js:173 |
indicator
页面视图指示器组件
| meta | description |
|---|---|
| 类型 | PageViewIndicator |
| 定义于 | cocos2d/core/components/CCPageView.js:185 |
pageTurningSpeed
每个页面翻页时所需时间。单位:秒
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/components/CCPageView.js:201 |
pageEvents
滚动视图的事件回调函数
| meta | description |
|---|---|
| 类型 | Component.EventHandler[] |
| 定义于 | cocos2d/core/components/CCPageView.js:212 |
content
可滚动展示内容的节点。
| meta | description |
|---|---|
| 类型 | Node |
| 定义于 | cocos2d/core/components/CCScrollView.js:206 |
horizontal
是否开启水平滚动。
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | cocos2d/core/components/CCScrollView.js:221 |
vertical
是否开启垂直滚动。
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | cocos2d/core/components/CCScrollView.js:232 |
inertia
是否开启滚动惯性。
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | cocos2d/core/components/CCScrollView.js:243 |
brake
开启惯性后,在用户停止触摸后滚动多快停止,0表示永不停止,1表示立刻停止。
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/components/CCScrollView.js:253 |
elastic
是否允许滚动内容超过边界,并在停止触摸后回弹。
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | cocos2d/core/components/CCScrollView.js:268 |
bounceDuration
回弹持续的时间,0 表示将立即反弹。
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/components/CCScrollView.js:279 |
horizontalScrollBar
水平滚动的 ScrollBar。
| meta | description |
|---|---|
| 类型 | Scrollbar |
| 定义于 | cocos2d/core/components/CCScrollView.js:290 |
verticalScrollBar
垂直滚动的 ScrollBar。
| meta | description |
|---|---|
| 类型 | Scrollbar |
| 定义于 | cocos2d/core/components/CCScrollView.js:308 |
scrollEvents
滚动视图的事件回调函数
| meta | description |
|---|---|
| 类型 | Component.EventHandler[] |
| 定义于 | cocos2d/core/components/CCScrollView.js:326 |
cancelInnerEvents
如果这个属性被设置为 true,那么滚动行为会取消子节点上注册的触摸事件,默认被设置为 true。 注意,子节点上的 touchstart 事件仍然会触发,触点移动距离非常短的情况下 touchmove 和 touchend 也不会受影响。
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | cocos2d/core/components/CCScrollView.js:337 |
__eventTargets
注册所有相关的 EventTargets,所有事件回调将在
_onPreDestroy中删除。
| meta | description |
|---|---|
| 类型 | Array |
| 定义于 | cocos2d/core/components/CCComponent.js:63 |
node
该组件被附加到的节点。组件总会附加到一个节点。
| meta | description |
|---|---|
| 类型 | Node |
| 定义于 | cocos2d/core/components/CCComponent.js:80 |
示例
cc.log(comp.node);
uuid
组件的 uuid,用于编辑器。
| meta | description |
|---|---|
| 类型 | String |
| 定义于 | cocos2d/core/components/CCComponent.js:111 |
示例
cc.log(comp.uuid);
_enabled
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | cocos2d/core/components/CCComponent.js:152 |
enabled
表示该组件自身是否启用。
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | cocos2d/core/components/CCComponent.js:159 |
示例
comp.enabled = true;
cc.log(comp.enabled);
enabledInHierarchy
表示该组件是否被启用并且所在的节点也处于激活状态。
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | cocos2d/core/components/CCComponent.js:191 |
示例
cc.log(comp.enabledInHierarchy);
_isOnLoadCalled
返回一个值用来判断 onLoad 是否被调用过,不等于 0 时调用过,等于 0 时未调用。
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/components/CCComponent.js:211 |
示例
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:240 |
示例
obj.name = "New Obj";
isValid
表示该对象是否可用(被 destroy 后将不可用)。
当一个对象的destroy调用以后,会在这一帧结束后才真正销毁。因此从下一帧开始isValid就会返回 false,而当前帧内isValid仍然会是 true。如果希望判断当前帧是否调用过destroy,请使用cc.isValid(obj, true),不过这往往是特殊的业务需求引起的,通常情况下不需要这样。
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | cocos2d/core/platform/CCObject.js:258 |
示例
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
方法
getCurrentPageIndex
返回当前页面索引
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/components/CCPageView.js:253 |
setCurrentPageIndex
设置当前页面索引
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCPageView.js:263 |
参数列表
indexNumber
getPages
返回视图中的所有页面
| meta | description |
|---|---|
| 返回 | Node[] |
| 定义于 | cocos2d/core/components/CCPageView.js:273 |
addPage
在当前页面视图的尾部插入一个新视图
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCPageView.js:283 |
参数列表
pageNode
insertPage
将页面插入指定位置中
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCPageView.js:297 |
参数列表
removePage
移除指定页面
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCPageView.js:317 |
参数列表
pageNode
removePageAtIndex
移除指定下标的页面
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCPageView.js:333 |
参数列表
indexNumber
removeAllPages
移除所有页面
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCPageView.js:349 |
scrollToPage
滚动到指定页面
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCPageView.js:363 |
参数列表
scrollToBottom
视图内容将在规定时间内滚动到视图底部。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:364 |
参数列表
timeInSecondNumber Scroll time in second, if you don't pass timeInSecond, the content will jump to the bottom boundary immediately.attenuatedBoolean Whether the scroll acceleration attenuated, default is true.
示例
// Scroll to the bottom of the view.
scrollView.scrollToBottom(0.1);
scrollToTop
视图内容将在规定时间内滚动到视图顶部。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:389 |
参数列表
timeInSecondNumber Scroll time in second, if you don't pass timeInSecond, the content will jump to the top boundary immediately.attenuatedBoolean Whether the scroll acceleration attenuated, default is true.
示例
// Scroll to the top of the view.
scrollView.scrollToTop(0.1);
scrollToLeft
视图内容将在规定时间内滚动到视图左边。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:414 |
参数列表
timeInSecondNumber Scroll time in second, if you don't pass timeInSecond, the content will jump to the left boundary immediately.attenuatedBoolean Whether the scroll acceleration attenuated, default is true.
示例
// Scroll to the left of the view.
scrollView.scrollToLeft(0.1);
scrollToRight
视图内容将在规定时间内滚动到视图右边。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:439 |
参数列表
timeInSecondNumber Scroll time in second, if you don't pass timeInSecond, the content will jump to the right boundary immediately.attenuatedBoolean Whether the scroll acceleration attenuated, default is true.
示例
// Scroll to the right of the view.
scrollView.scrollToRight(0.1);
scrollToTopLeft
视图内容将在规定时间内滚动到视图左上角。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:464 |
参数列表
timeInSecondNumber Scroll time in second, if you don't pass timeInSecond, the content will jump to the top left boundary immediately.attenuatedBoolean Whether the scroll acceleration attenuated, default is true.
示例
// Scroll to the upper left corner of the view.
scrollView.scrollToTopLeft(0.1);
scrollToTopRight
视图内容将在规定时间内滚动到视图右上角。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:489 |
参数列表
timeInSecondNumber Scroll time in second, if you don't pass timeInSecond, the content will jump to the top right boundary immediately.attenuatedBoolean Whether the scroll acceleration attenuated, default is true.
示例
// Scroll to the top right corner of the view.
scrollView.scrollToTopRight(0.1);
scrollToBottomLeft
视图内容将在规定时间内滚动到视图左下角。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:514 |
参数列表
timeInSecondNumber Scroll time in second, if you don't pass timeInSecond, the content will jump to the bottom left boundary immediately.attenuatedBoolean Whether the scroll acceleration attenuated, default is true.
示例
// Scroll to the lower left corner of the view.
scrollView.scrollToBottomLeft(0.1);
scrollToBottomRight
视图内容将在规定时间内滚动到视图右下角。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:539 |
参数列表
timeInSecondNumber Scroll time in second, if you don't pass timeInSecond, the content will jump to the bottom right boundary immediately.attenuatedBoolean Whether the scroll acceleration attenuated, default is true.
示例
// Scroll to the lower right corner of the view.
scrollView.scrollToBottomRight(0.1);
scrollToOffset
视图内容在规定时间内将滚动到 ScrollView 相对左上角原点的偏移位置, 如果 timeInSecond参数不传,则立即滚动到指定偏移位置。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:565 |
参数列表
offsetVec2 A Vec2, the value of which each axis between 0 and maxScrollOffsettimeInSecondNumber Scroll time in second, if you don't pass timeInSecond, the content will jump to the specific offset of ScrollView immediately.attenuatedBoolean Whether the scroll acceleration attenuated, default is true.
示例
// Scroll to middle position in 0.1 second in x-axis
let maxScrollOffset = this.getMaxScrollOffset();
scrollView.scrollToOffset(cc.v2(maxScrollOffset.x / 2, 0), 0.1);
getScrollOffset
获取滚动视图相对于左上角原点的当前滚动偏移
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/components/CCScrollView.js:599 |
getMaxScrollOffset
获取滚动视图最大可以滚动的偏移量
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/components/CCScrollView.js:612 |
scrollToPercentHorizontal
视图内容在规定时间内将滚动到 ScrollView 水平方向的百分比位置上。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:629 |
参数列表
percentNumber A value between 0 and 1.timeInSecondNumber Scroll time in second, if you don't pass timeInSecond, the content will jump to the horizontal percent position of ScrollView immediately.attenuatedBoolean Whether the scroll acceleration attenuated, default is true.
示例
// Scroll to middle position.
scrollView.scrollToBottomRight(0.5, 0.1);
scrollTo
视图内容在规定时间内进行垂直方向和水平方向的滚动,并且滚动到指定百分比位置上。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:655 |
参数列表
anchorVec2 A point which will be clamp between cc.v2(0,0) and cc.v2(1,1).timeInSecondNumber Scroll time in second, if you don't pass timeInSecond, the content will jump to the percent position of ScrollView immediately.attenuatedBoolean Whether the scroll acceleration attenuated, default is true.
示例
// Vertical scroll to the bottom of the view.
scrollView.scrollTo(cc.v2(0, 1), 0.1);
// Horizontal scroll to view right.
scrollView.scrollTo(cc.v2(1, 0), 0.1);
scrollToPercentVertical
视图内容在规定时间内滚动到 ScrollView 垂直方向的百分比位置上。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:684 |
参数列表
percentNumber A value between 0 and 1.timeInSecondNumber Scroll time in second, if you don't pass timeInSecond, the content will jump to the vertical percent position of ScrollView immediately.attenuatedBoolean Whether the scroll acceleration attenuated, default is true. // Scroll to middle position. scrollView.scrollToPercentVertical(0.5, 0.1);
stopAutoScroll
停止自动滚动, 调用此 API 可以让 Scrollview 立即停止滚动
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:709 |
setContentPosition
设置当前视图内容的坐标点。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCScrollView.js:719 |
参数列表
positionVec2 The position in content's parent space.
getContentPosition
获取当前视图内容的坐标点。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/components/CCScrollView.js:734 |
isScrolling
用户是否在拖拽当前滚动视图
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/components/CCScrollView.js:744 |
isAutoScrolling
当前滚动视图是否在惯性滚动
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/components/CCScrollView.js:754 |
hasNestedViewGroup
此 Scoll View 是否含有嵌套的 View Group
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/components/CCScrollView.js:915 |
update
如果该组件启用,则每帧调用 update。
该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:232 |
参数列表
dtNumber the delta time in seconds it took to complete the last frame
lateUpdate
如果该组件启用,则每帧调用 LateUpdate。
该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:243 |
参数列表
dtNumber the delta time in seconds it took to complete the last frame
__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:254 |
onLoad
当附加到一个激活的节点上或者其节点第一次激活时候调用。onLoad 总是会在任何 start 方法调用前执行,这能用于安排脚本的初始化顺序。
该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:265 |
start
如果该组件第一次启用,则在所有组件的 update 之前调用。通常用于需要在所有组件的 onLoad 初始化完毕后执行的逻辑。
该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:278 |
onEnable
当该组件被启用,并且它的节点也激活时。
该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:291 |
onDisable
当该组件被禁用或节点变为无效时调用。
该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:301 |
onDestroy
当该组件被销毁时调用
该方法为生命周期方法,父类未必会有实现。并且你只能在该方法内部调用父类的实现,不可在其它地方直接调用该方法。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:311 |
onFocusInEditor
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:321 |
onLostFocusInEditor
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:326 |
resetInEditor
用来初始化组件或节点的一些属性,当该组件被第一次添加到节点上或用户点击了它的 Reset 菜单时调用。这个回调只会在编辑器下调用。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:331 |
addComponent
向节点添加一个组件类,你还可以通过传入脚本的名称来添加组件。
| meta | description |
|---|---|
| 返回 | Component |
| 定义于 | cocos2d/core/components/CCComponent.js:341 |
参数列表
示例
var sprite = node.addComponent(cc.Sprite);
var test = node.addComponent("Test");
getComponent
获取节点上指定类型的组件,如果节点有附加指定类型的组件,则返回,如果没有则为空。
传入参数也可以是脚本的名称。
| meta | description |
|---|---|
| 返回 | Component |
| 定义于 | cocos2d/core/components/CCComponent.js:359 |
参数列表
示例
// 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:383 |
参数列表
示例
var sprites = node.getComponents(cc.Sprite);
var tests = node.getComponents("Test");
getComponentInChildren
递归查找所有子节点中第一个匹配指定类型的组件。
| meta | description |
|---|---|
| 返回 | Component |
| 定义于 | cocos2d/core/components/CCComponent.js:401 |
参数列表
示例
var sprite = node.getComponentInChildren(cc.Sprite);
var Test = node.getComponentInChildren("Test");
getComponentsInChildren
递归查找自身或所有子节点中指定类型的组件
| meta | description |
|---|---|
| 返回 | Component[] |
| 定义于 | cocos2d/core/components/CCComponent.js:419 |
参数列表
示例
var sprites = node.getComponentsInChildren(cc.Sprite);
var tests = node.getComponentsInChildren("Test");
_getLocalBounds
如果组件的包围盒与节点不同,您可以实现该方法以提供自定义的轴向对齐的包围盒(AABB), 以便编辑器的场景视图可以正确地执行点选测试。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:439 |
参数列表
out_rectRect the Rect to receive the bounding box
onRestore
onRestore 是用户在检查器菜单点击 Reset 时,对此组件执行撤消操作后调用的。
如果组件包含了“内部状态”(不在 CCClass 属性中定义的临时成员变量),那么你可能需要实现该方法。
编辑器执行撤销/重做操作时,将调用组件的 get set 来录制和还原组件的状态。然而,在极端的情况下,它可能无法良好运作。
那么你就应该实现这个方法,手动根据组件的属性同步“内部状态”。一旦你实现这个方法,当用户撤销或重做时,组件的所有 get set 都不会再被调用。这意味着仅仅指定了默认值的属性将被编辑器记录和还原。
同样的,编辑可能无法在极端情况下正确地重置您的组件。如果你需要支持组件重置菜单,则需要在该方法中手工同步组件属性到“内部状态”。一旦你实现这个方法,组件的所有 get set 都不会在重置操作时被调用。这意味着仅仅指定了默认值的属性将被编辑器重置。
此方法仅在编辑器下会被调用。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:452 |
schedule
调度一个自定义的回调函数。
如果回调函数已调度,那么将不会重复调度它,只会更新时间间隔参数。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:544 |
参数列表
callbackfunction The callback functionintervalNumber Tick interval in seconds. 0 means tick every frame.repeatNumber The selector will be executed (repeat + 1) times, you can use cc.macro.REPEAT_FOREVER for tick infinitely.delayNumber The amount of time that the first tick will wait before execution. Unit: s
示例
var timeCallback = function (dt) {
cc.log("time: " + dt);
}
this.schedule(timeCallback, 1);
scheduleOnce
调度一个只运行一次的回调函数,可以指定 0 让回调函数在下一帧立即执行或者在一定的延时之后执行。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:582 |
参数列表
callbackfunction A function wrapped as a selectordelayNumber The amount of time that the first tick will wait before execution. Unit: s
示例
var timeCallback = function (dt) {
cc.log("time: " + dt);
}
this.scheduleOnce(timeCallback, 2);
unschedule
取消调度一个自定义的回调函数。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:599 |
参数列表
callback_fnfunction A function wrapped as a selector
示例
this.unschedule(_callback);
unscheduleAllCallbacks
取消调度所有已调度的回调函数:定制的回调函数以及 update 回调函数。动作不受此方法影响。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/components/CCComponent.js:615 |
示例
this.unscheduleAllCallbacks();
destroy
销毁该对象,并释放所有它对其它对象的引用。
实际销毁操作会延迟到当前帧渲染前执行。从下一帧开始,该对象将不再可用。
您可以在访问对象之前使用 cc.isValid(obj) 来检查对象是否已被销毁。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/platform/CCObject.js:293 |
示例
obj.destroy();
_destruct
清除实例中的所有引用。
注意:此方法不会清除在 CCObject 实例中定义的 getter 或 setter。如果需要,你可以重写 _destruct 方法。例如:
_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:427 |
_onPreDestroy
在对象被销毁之前调用。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCObject.js:483 |
_serialize
为此对象定制序列化。
| meta | description |
|---|---|
| 返回 | object |
| 定义于 | cocos2d/core/platform/CCObject.js:511 |
参数列表
exportingBoolean
_deserialize
从自定义序列化数据初始化此对象。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCObject.js:524 |
参数列表
dataObject the serialized json datactx_Deserializer
事件
page-turning Event
模块: cc
注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
索引
Details
scroll-to-top Event
模块: cc
注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
索引
Details
scroll-to-bottom Event
模块: cc
注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
索引
Details
scroll-to-left Event
模块: cc
注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
索引
Details
scroll-to-right Event
模块: cc
注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
索引
Details
scrolling Event
模块: cc
注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
索引
Details
bounce-bottom Event
模块: cc
注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
索引
Details
bounce-top Event
模块: cc
注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
索引
Details
bounce-left Event
模块: cc
注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
索引
Details
bounce-right Event
模块: cc
注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
索引
Details
scroll-ended Event
模块: cc
注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
索引
Details
touch-up Event
模块: cc
注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。
索引
Details
scroll-began Event
模块: cc
注意:此事件是从该组件所属的 Node 上面派发出来的,需要用 node.on 来监听。