this.pageview = this.node.getComponent(cc.PageView);
this.node.on('page-turning', this.pageview_callback, this); //滚动回调
this.pageview.setCurrentPageIndex(this.pageview_index);//设置到第几页
this.pageview_length = this.pageview.getPages().length;//获取多少pageview
this.pageview.getCurrentPageIndex());//获得当前的页数
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property({type: cc.PageView})
banner:cc.PageView=null;
@property
_pageIdx = 0;
onLoad () {
}
start () {
}
onEnable () {
this.schedule(this.schdulePageView, 5);
}
onDisable () {
this.unschedule(this.schdulePageView);
}
/**
* 循环播放广告
*/
schdulePageView () {
if (this._pageIdx >= this.banner.getPages().length) {
this._pageIdx = 0;
}
this.banner.setCurrentPageIndex(this._pageIdx);
cc.log(this.banner.getCurrentPageIndex());//获得当前的页数
this._pageIdx+=1;
}
// update (dt) {}
}
代码导出为:http://note.youdao.com/noteshare?id=ed1e33093188f6f3c28ef504663fb9df&sub=3E5C420615934CD199D51AC8C599DCE0
下载后,文件-》资源导入