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