Commit 5a8a6069 authored by huoshizhe's avatar huoshizhe

feat: 页面跳转逻辑

parent 9885859f
// Learn cc.Class:
// - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
cc.Class({
extends: cc.Component,
......@@ -29,51 +22,38 @@ cc.Class({
BtnPrevious.active = true;
if (!this._dataList[this._currentIdx + 1]) {
console.log('汪汪汪')
BtnNext.active = false;
}
if (!this._dataList[this._currentIdx - 1]) {
console.log('喵喵喵')
BtnPrevious.active = false;
}
cc.resources.load('prefabs/ButtonsNode', cc.Prefab, (err, ButtonsNode) => {
const dataList = this._dataList;
const currentIdx = this._currentIdx;
BtnNext.on('click', () => {
let demoItem = this._dataList[this._currentIdx + 1];
cc.director.loadScene(demoItem.sceneName, () => {
const newButtonNode = cc.instantiate(ButtonsNode);
newButtonNode.parent = cc.find('Canvas');
newButtonNode.x = 0;
newButtonNode.y = 0;
newButtonNode.getComponent('ButtonsNode').setDataList(dataList, currentIdx + 1);
this.node.getComponent('ButtonsNode').setDataList(this._dataList, this._currentIdx + 1);
});
});
BtnPrevious.on('click', () => {
let demoItem = this._dataList[this._currentIdx - 1];
cc.director.loadScene(demoItem.sceneName, () => {
const newButtonNode = cc.instantiate(ButtonsNode);
newButtonNode.parent = cc.find('Canvas');
newButtonNode.x = 0;
newButtonNode.y = 0;
newButtonNode.getComponent('ButtonsNode').setDataList(dataList, currentIdx - 1);
this.node.getComponent('ButtonsNode').setDataList(this._dataList, this._currentIdx - 1);
});
});
BtnBack.on('click', () => {
cc.game.removePersistRootNode(this.node);
this.node.active = false;
cc.director.loadScene('unit_demo');
});
});
},
setDataList(dataList, currentIdx) {
console.log('dataList = ' + JSON.stringify(dataList));
console.log('currentIdx = ' + JSON.stringify(currentIdx));
this._dataList = dataList;
this._currentIdx = currentIdx;
this.initListeners();
},
// update (dt) {},
});
......@@ -307,7 +307,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "NEXT --->",
"_N$string": "NEXT --->",
"_fontSize": 20,
......@@ -748,7 +747,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "<---PREVIOUS",
"_N$string": "<---PREVIOUS",
"_fontSize": 20,
......@@ -1189,7 +1187,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "back",
"_N$string": "back",
"_fontSize": 20,
......@@ -1417,7 +1414,7 @@
"__id__": 1
},
"_children": [],
"_active": false,
"_active": true,
"_components": [
{
"__id__": 36
......@@ -1534,7 +1531,7 @@
"asset": {
"__uuid__": "ffa620db-880d-4ed4-8dd1-00133559ac52"
},
"fileId": "d7OJrcCmJLEIoN3nqNXoZJ",
"fileId": "",
"sync": false
}
]
\ No newline at end of file
......@@ -448,7 +448,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "发射",
"_N$string": "发射",
"_fontSize": 20,
......
......@@ -107,8 +107,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 960,
"height": 640
"width": 1280,
"height": 720
},
"_anchorPoint": {
"__type__": "cc.Vec2",
......@@ -119,8 +119,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
480,
320,
640,
360,
0,
0,
0,
......@@ -169,8 +169,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 960,
"height": 640
"width": 1280,
"height": 720
},
"_anchorPoint": {
"__type__": "cc.Vec2",
......@@ -282,8 +282,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
440,
280,
600,
320,
0,
0,
0,
......@@ -411,7 +411,7 @@
"ctor": "Float64Array",
"array": [
200,
-270,
-310,
0,
0,
0,
......@@ -581,7 +581,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "播放",
"_N$string": "播放",
"_fontSize": 20,
......@@ -813,7 +812,7 @@
"ctor": "Float64Array",
"array": [
-200,
-270,
-310,
0,
0,
0,
......@@ -983,7 +982,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "增加星星",
"_N$string": "增加星星",
"_fontSize": 20,
......@@ -1180,8 +1178,8 @@
"_enabled": true,
"_designResolution": {
"__type__": "cc.Size",
"width": 960,
"height": 640
"width": 1280,
"height": 720
},
"_fitWidth": false,
"_fitHeight": true,
......
......@@ -110,8 +110,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 960,
"height": 640
"width": 1280,
"height": 720
},
"_anchorPoint": {
"__type__": "cc.Vec2",
......@@ -122,8 +122,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
480,
320,
640,
360,
0,
0,
0,
......@@ -172,8 +172,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 960,
"height": 640
"width": 1280,
"height": 720
},
"_anchorPoint": {
"__type__": "cc.Vec2",
......@@ -504,7 +504,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "(点击屏幕撒花)",
"_N$string": "(点击屏幕撒花)",
"_fontSize": 40,
......@@ -735,7 +734,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "全屏撒花",
"_N$string": "全屏撒花",
"_fontSize": 20,
......@@ -905,8 +903,8 @@
"_enabled": true,
"_designResolution": {
"__type__": "cc.Size",
"width": 960,
"height": 640
"width": 1280,
"height": 720
},
"_fitWidth": false,
"_fitHeight": true,
......
......@@ -101,8 +101,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 960,
"height": 640
"width": 1280,
"height": 720
},
"_anchorPoint": {
"__type__": "cc.Vec2",
......@@ -113,8 +113,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
480,
320,
640,
360,
0,
0,
0,
......@@ -163,8 +163,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 960,
"height": 640
"width": 1280,
"height": 720
},
"_anchorPoint": {
"__type__": "cc.Vec2",
......@@ -341,8 +341,8 @@
"_enabled": true,
"_designResolution": {
"__type__": "cc.Size",
"width": 960,
"height": 640
"width": 1280,
"height": 720
},
"_fitWidth": false,
"_fitHeight": true,
......
......@@ -101,8 +101,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 960,
"height": 640
"width": 1280,
"height": 720
},
"_anchorPoint": {
"__type__": "cc.Vec2",
......@@ -113,8 +113,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
480,
320,
640,
360,
0,
0,
0,
......@@ -163,8 +163,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 960,
"height": 640
"width": 1280,
"height": 720
},
"_anchorPoint": {
"__type__": "cc.Vec2",
......@@ -407,7 +407,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "点击字母A白色的部分,触发事件;\n点击透明的部分,不触发。",
"_N$string": "点击字母A白色的部分,触发事件;\n点击透明的部分,不触发。",
"_fontSize": 40,
......@@ -436,8 +435,8 @@
"_enabled": true,
"_designResolution": {
"__type__": "cc.Size",
"width": 960,
"height": 640
"width": 1280,
"height": 720
},
"_fitWidth": false,
"_fitHeight": true,
......
......@@ -2078,9 +2078,9 @@
"_opacity": 100,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 112,
"b": 244,
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
......@@ -2090,8 +2090,8 @@
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
"x": 0,
"y": 0
},
"_trs": {
"__type__": "TypedArray",
......
......@@ -22,7 +22,7 @@ cc.Class({
preloadItem() {
this.preload();
this.onLoadFinish();
this.initView();
},
preload() {
......@@ -36,7 +36,7 @@ cc.Class({
}
},
onLoadFinish() {
initView() {
const demoList = [{
sceneName: 'demo_01_showFireworks',
......@@ -55,6 +55,9 @@ cc.Class({
label: '透明判断'
}];
const buttonsNode = cc.find('ButtonsNode');
cc.game.addPersistRootNode(buttonsNode);
demoList.forEach((demoItem, idx) => {
const button = cc.instantiate(cc.find('Canvas/New Button'));
const label = cc.find('Background/Label', button);
......@@ -69,14 +72,8 @@ cc.Class({
button.on('click', () => {
cc.director.loadScene(demoItem.sceneName, () => {
cc.resources.load('prefabs/ButtonsNode', cc.Prefab, function (err, ButtonsNode) {
const newButtonNode = cc.instantiate(ButtonsNode);
newButtonNode.getComponent('ButtonsNode').setDataList(demoList, idx);
newButtonNode.parent = cc.find('Canvas');
newButtonNode.x = 0;
newButtonNode.y = 0;
});
buttonsNode.active = true;
buttonsNode.getComponent('ButtonsNode').setDataList(demoList, idx);
});
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment