Commit 8e467e99 authored by 范雪寒's avatar 范雪寒

feat: 菜单控制组件完成

parent eaa67fb7
...@@ -18,7 +18,6 @@ cc.Class({ ...@@ -18,7 +18,6 @@ cc.Class({
}, },
start() { start() {
this.initListeners();
}, },
initListeners() { initListeners() {
...@@ -26,44 +25,54 @@ cc.Class({ ...@@ -26,44 +25,54 @@ cc.Class({
const BtnPrevious = this.node.getChildByName('BtnPrevious'); const BtnPrevious = this.node.getChildByName('BtnPrevious');
const BtnBack = this.node.getChildByName('BtnBack'); const BtnBack = this.node.getChildByName('BtnBack');
const buttonsNode = cc.find('ButtonsNode'); BtnNext.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]) {
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', () => { BtnNext.on('click', () => {
demoItem = this._dataList[this._currentIdx + 1]; demoItem = this._dataList[this._currentIdx + 1];
cc.director.loadScene(demoItem.sceneName, () => { cc.director.loadScene(demoItem.sceneName, () => {
const scene = cc.director.getScene(); const newButtonNode = cc.instantiate(ButtonsNode);
const newButtonNode = cc.instantiate(buttonsNode); newButtonNode.parent = cc.find('Canvas');
newButtonNode.parent = scene;
newButtonNode.x = 0; newButtonNode.x = 0;
newButtonNode.y = 0; newButtonNode.y = 0;
newButtonNode.getComponent('ButtonsNode').setDataList(demoList, idx); newButtonNode.getComponent('ButtonsNode').setDataList(dataList, currentIdx + 1);
}); });
}); });
if (!this._dataList[this._currentIdx - 1]) {
BtnPrevious.active = false;
}
BtnPrevious.on('click', () => { BtnPrevious.on('click', () => {
demoItem = this._dataList[this._currentIdx - 1]; demoItem = this._dataList[this._currentIdx - 1];
cc.director.loadScene(demoItem.sceneName, () => { cc.director.loadScene(demoItem.sceneName, () => {
const scene = cc.director.getScene(); const newButtonNode = cc.instantiate(ButtonsNode);
const newButtonNode = cc.instantiate(buttonsNode); newButtonNode.parent = cc.find('Canvas');
newButtonNode.parent = scene;
newButtonNode.x = 0; newButtonNode.x = 0;
newButtonNode.y = 0; newButtonNode.y = 0;
newButtonNode.getComponent('ButtonsNode').setDataList(demoList, idx); newButtonNode.getComponent('ButtonsNode').setDataList(dataList, currentIdx - 1);
}); });
}); });
BtnBack.on('click', () => { BtnBack.on('click', () => {
cc.director.loadScene('mainPage'); cc.director.loadScene('mainPage');
}); });
});
}, },
setDataList(dataList, currentIdx) { setDataList(dataList, currentIdx) {
this._dataList = dataList; this._dataList = dataList;
this._currentIdx = currentIdx; this._currentIdx = currentIdx;
this.initListeners();
}, },
// update (dt) {}, // update (dt) {},
......
...@@ -25,16 +25,19 @@ ...@@ -25,16 +25,19 @@
}, },
{ {
"__id__": 24 "__id__": 24
},
{
"__id__": 35
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 35 "__id__": 38
} }
], ],
"_prefab": { "_prefab": {
"__id__": 36 "__id__": 39
}, },
"_opacity": 255, "_opacity": 255,
"_color": { "_color": {
...@@ -1406,6 +1409,113 @@ ...@@ -1406,6 +1409,113 @@
"fileId": "aa1/O6kH1CT62jMktS6TUP", "fileId": "aa1/O6kH1CT62jMktS6TUP",
"sync": false "sync": false
}, },
{
"__type__": "cc.Node",
"_name": "New Sprite(Splash)",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": false,
"_components": [
{
"__id__": 36
}
],
"_prefab": {
"__id__": 37
},
"_opacity": 100,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 112,
"b": 244,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 1280,
"height": 720
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 35
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "a23235d1-15db-4b95-8439-a2e005bfff91"
},
"_type": 0,
"_sizeMode": 0,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "ffa620db-880d-4ed4-8dd1-00133559ac52"
},
"fileId": "e04yZ0G1dPgoekC5dZ6w45",
"sync": false
},
{ {
"__type__": "abb52OcegZE5rPyTByt2ykw", "__type__": "abb52OcegZE5rPyTByt2ykw",
"_name": "", "_name": "",
......
// 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,
properties: {
// foo: {
// // ATTRIBUTES:
// default: null, // The default value will be used only when the component attaching
// // to a node for the first time
// type: cc.SpriteFrame, // optional, default is typeof default
// serializable: true, // optional, default is true
// },
// bar: {
// get () {
// return this._bar;
// },
// set (value) {
// this._bar = value;
// }
// },
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
start () {
},
// update (dt) {},
});
{
"ver": "1.0.8",
"uuid": "a6c50b72-661b-43cf-bfae-419ac3306e3e",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
...@@ -20,6 +20,9 @@ cc.Class({ ...@@ -20,6 +20,9 @@ cc.Class({
const demoList = [{ const demoList = [{
sceneName: 'demo_01_showFireworks', sceneName: 'demo_01_showFireworks',
label: '烟花效果' label: '烟花效果'
}, {
sceneName: 'demo_01_showFireworks',
label: '烟花效果'
}]; }];
demoList.forEach((demoItem, idx) => { demoList.forEach((demoItem, idx) => {
...@@ -34,16 +37,16 @@ cc.Class({ ...@@ -34,16 +37,16 @@ cc.Class({
button.x = (width / widthLength) * ((idx % widthLength) - (widthLength - 1) / 2); button.x = (width / widthLength) * ((idx % widthLength) - (widthLength - 1) / 2);
button.y = 300 - Math.floor(idx / widthLength) * 50; button.y = 300 - Math.floor(idx / widthLength) * 50;
const buttonsNode = cc.find('ButtonsNode');
button.on('click', () => { button.on('click', () => {
cc.director.loadScene(demoItem.sceneName, () => { cc.director.loadScene(demoItem.sceneName, () => {
const scene = cc.director.getScene(); cc.resources.load('prefabs/ButtonsNode', cc.Prefab, function (err, ButtonsNode) {
const newButtonNode = cc.instantiate(buttonsNode); const newButtonNode = cc.instantiate(ButtonsNode);
newButtonNode.parent = scene; newButtonNode.getComponent('ButtonsNode').setDataList(demoList, idx);
newButtonNode.parent = cc.find('Canvas');
newButtonNode.x = 0; newButtonNode.x = 0;
newButtonNode.y = 0; newButtonNode.y = 0;
newButtonNode.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