1.适用的情况
左右滑动式滚动区的关卡界面
2.实现的思路
关卡按钮使用预制文件,在进入关卡时动态生成。
根据关卡总数计算滚动区的大小。
根据当前关卡序号设置滚动区的位置和表示分页的点的显示。
3.控件布局
Canvas
--scrollView
--view
--content
--pointNode
--point1
--red
--black
--point2
--point3
--point4
--point5
--point6
4.代码
Common.js-------------------
module.exports = {
currentLevel: 1, //当前关卡
maxLevel: 29, //关卡总数
};
Level.js-------------------
var common = require('zqddn_zhb_Common');
cc.Class({
extends: cc.Component,
properties: {
scrollViewNode: cc.Node, //滚动区节点
scrollViewContentNode: cc.Node, //滚动区内容节点
linePrefab: cc.Prefab, //线预制
levelBtnPrefab: cc.Prefab, //关卡按钮预制
pointNode: { default: [], type: cc.Node }, //点节点
},
onLoad: function() {
this.first = true; //第1次
this.only1 = true; //只一次
this.only2 = true;
this.only3 = true;
this.currentPageIndex = 0; //当前滚动页序号
this.direction = 0; //滚动方向(0默认,1左,2右)
this.startOffset = 0; //开始滚动时第1帧
this.endOffset = 0; //开始滚动时第2帧
//根据关卡数设置滚动区大小
this.pageCount = Math.ceil(common.maxLevel / 12);
this.scrollViewContentNode.width = 750 * this.pageCount;
//添加线
for(var i = 0; i < this.pageCount; i++){
for(var j = 0; j < 4; j++){
var line = cc.instantiate(this.linePrefab);
this.scrollViewContentNode.addChild(line);
line.setPositio
左右滑动式滚动区的关卡界面
2.实现的思路
关卡按钮使用预制文件,在进入关卡时动态生成。
根据关卡总数计算滚动区的大小。
根据当前关卡序号设置滚动区的位置和表示分页的点的显示。
3.控件布局
Canvas
--scrollView
--view
--content
--pointNode
--point1
--red
--black
--point2
--point3
--point4
--point5
--point6
4.代码
Common.js-------------------
module.exports = {
currentLevel: 1, //当前关卡
maxLevel: 29, //关卡总数
};
Level.js-------------------
var common = require('zqddn_zhb_Common');
cc.Class({
extends: cc.Component,
properties: {
scrollViewNode: cc.Node, //滚动区节点
scrollViewContentNode: cc.Node, //滚动区内容节点
linePrefab: cc.Prefab, //线预制
levelBtnPrefab: cc.Prefab, //关卡按钮预制
pointNode: { default: [], type: cc.Node }, //点节点
},
onLoad: function() {
this.first = true; //第1次
this.only1 = true; //只一次
this.only2 = true;
this.only3 = true;
this.currentPageIndex = 0; //当前滚动页序号
this.direction = 0; //滚动方向(0默认,1左,2右)
this.startOffset = 0; //开始滚动时第1帧
this.endOffset = 0; //开始滚动时第2帧
//根据关卡数设置滚动区大小
this.pageCount = Math.ceil(common.maxLevel / 12);
this.scrollViewContentNode.width = 750 * this.pageCount;
//添加线
for(var i = 0; i < this.pageCount; i++){
for(var j = 0; j < 4; j++){
var line = cc.instantiate(this.linePrefab);
this.scrollViewContentNode.addChild(line);
line.setPositio