Commit 8b4b0a51 authored by Tt's avatar Tt

feat(场景): 扩展页面数量并优化页面管理逻辑

parent a9cc2e7d
This diff is collapsed.
...@@ -136,6 +136,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -136,6 +136,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
@property({ displayName: "提示手指节点", type: cc.Node }) btn_finger: cc.Node = null; @property({ displayName: "提示手指节点", type: cc.Node }) btn_finger: cc.Node = null;
@property({ displayName: "页面a", type: cc.Node }) page_a: cc.Node = null; @property({ displayName: "页面a", type: cc.Node }) page_a: cc.Node = null;
@property({ displayName: "页面b", type: cc.Node }) page_b: cc.Node = null; @property({ displayName: "页面b", type: cc.Node }) page_b: cc.Node = null;
@property({ displayName: "页面c", type: cc.Node }) page_c: cc.Node = null;
@property({ displayName: "页面d", type: cc.Node }) page_d: cc.Node = null;
@property({ displayName: "页面e", type: cc.Node }) page_e: cc.Node = null;
@property({ displayName: "页面f", type: cc.Node }) page_f: cc.Node = null;
@property({ displayName: "页面g", type: cc.Node }) page_g: cc.Node = null;
@property({ displayName: "关闭录音界面按钮", type: cc.Node }) btn_close: cc.Node = null; @property({ displayName: "关闭录音界面按钮", type: cc.Node }) btn_close: cc.Node = null;
// 游戏数据相关变量 // 游戏数据相关变量
...@@ -221,6 +226,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -221,6 +226,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (this.page_b) { if (this.page_b) {
this.page_b.active = false; this.page_b.active = false;
} }
if (this.page_c) {
this.page_c.active = false;
}
} }
/** 音频播放ID */ /** 音频播放ID */
private audioId: any; private audioId: any;
...@@ -248,12 +256,14 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -248,12 +256,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.isHintAnimPlaying = false; this.isHintAnimPlaying = false;
this.inactiveTimer = 0; this.inactiveTimer = 0;
const currentPage = 0; // 初始化所有页面位置
const currentPageNode = currentPage % 2 === 0 ? this.page_a : this.page_b; this.page_a.x = 0;
const otherPageNode = currentPage % 2 === 0 ? this.page_b : this.page_a; this.page_b.x = 1920;
currentPageNode.x = 0; this.page_c.x = 3840;
otherPageNode.x = 1920; this.page_d.x = 5760;
this.page_e.x = 7680;
this.page_f.x = 9600;
this.page_g.x = 11520;
} }
/** /**
* 初始化事件监听 * 初始化事件监听
...@@ -343,7 +353,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -343,7 +353,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
/** /**
* 显示当前页面 * 显示当前页面
* 根据当前页码决定使用page_a还是page_b * 使用page_a、page_b、page_c三个页面循环显示
* 并设置fire_0到fire_5这6个交互点 * 并设置fire_0到fire_5这6个交互点
* 当前页面的内容完成后,layout_game会向左移动一页的距离(1920) * 当前页面的内容完成后,layout_game会向左移动一页的距离(1920)
*/ */
...@@ -352,14 +362,14 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -352,14 +362,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
const currentPage = Game.getIns().getCurrentPageNum(); const currentPage = Game.getIns().getCurrentPageNum();
const prevPage = currentPage - 1; const prevPage = currentPage - 1;
// 根据页码的奇偶性决定使用哪个页面 // 使用三个页面循环:page_a, page_b, page_c
// 偶数页使用page_a,奇数页使用page_b const pages = [this.page_a, this.page_b, this.page_c, this.page_d, this.page_e, this.page_f, this.page_g];
const currentPageNode = currentPage % 2 === 0 ? this.page_a : this.page_b; const currentPageNode = pages[currentPage];
const otherPageNode = currentPage % 2 === 0 ? this.page_b : this.page_a;
// 显示当前页面,隐藏另一个页面 // 显示所有页面
currentPageNode.active = true; this.page_a.active = true;
otherPageNode.active = true; this.page_b.active = true;
this.page_c.active = true;
// 获取当前页的数据 // 获取当前页的数据
const pageData = Game.getIns().getPageData(); const pageData = Game.getIns().getPageData();
...@@ -393,18 +403,20 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -393,18 +403,20 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 如果不是第一页,则添加layout_game向左移动的动画 // 如果不是第一页,则添加layout_game向左移动的动画
if (prevPage >= 0) { if (prevPage >= 0) {
// 使用cc.tween实现layout_game向左移动一页的距离(1920) this.moveTruck(currentPage);
cc.tween(this.layout_game)
.to(3.0, { x: -1920 * currentPage }, { easing: 'cubicOut' })
.call(() => {
otherPageNode.x = 1920 * (currentPage + 1);
})
.start();
cc.tween(this.node_firetruck)
.to(3.0, { x: -400 + 1920 * currentPage }, { easing: 'cubicOut' })
.start();
} }
} }
moveTruck(currentPage: number) {
// 使用cc.tween实现layout_game向左移动一页的距离(1920)
cc.tween(this.layout_game)
.to(3.0, { x: -1920 * currentPage }, { easing: 'cubicOut' })
.call(() => {
})
.start();
cc.tween(this.node_firetruck)
.to(3.0, { x: -400 + 1920 * currentPage }, { easing: 'cubicOut' })
.start();
}
/** /**
* 消防车点击事件处理 * 消防车点击事件处理
* 随机选择一个存在的火苗并触发相应的事件 * 随机选择一个存在的火苗并触发相应的事件
...@@ -517,10 +529,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -517,10 +529,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 获取当前页面节点 // 获取当前页面节点
const currentPage = Game.getIns().getCurrentPageNum(); const currentPage = Game.getIns().getCurrentPageNum();
const currentPageNode = currentPage % 2 === 0 ? this.page_a : this.page_b; const pages = [this.page_a, this.page_b, this.page_c, this.page_d, this.page_e, this.page_f, this.page_g]
const currentPageNode = pages[currentPage];
// 查找并显示对应的water节点 // 查找并显示对应的water节点
const waterNode = cc.find(`water_${fireIndex}`, currentPageNode); const waterNode = currentPageNode.getChildByName(`water_${fireIndex}`);
if (waterNode) { if (waterNode) {
waterNode.active = true; waterNode.active = true;
} else { } else {
......
...@@ -33,69 +33,69 @@ export const defaultData = { ...@@ -33,69 +33,69 @@ export const defaultData = {
"time": null, "time": null,
"duration": "", "duration": "",
"audioName": "egg.mp3" "audioName": "egg.mp3"
},
{
"type": "txt",
"audio": "https://staging-teach.cdn.ireadabc.com/8d6a8d7764011afb0ef537d5a44d1d10_l.mp3",
"text": "key",
"image": "https://staging-teach.cdn.ireadabc.com/ab9962445d23c0df3a021ae3996412bc.png",
"time": null,
"duration": "",
"audioName": "key.mp3"
},
{
"type": "img",
"audio": "https://staging-teach.cdn.ireadabc.com/e634280a803a6c9d0b0b51b41f017254_l.mp3",
"text": "lion",
"image": "https://staging-teach.cdn.ireadabc.com/26a3965f155e85980be316c077a93004.png",
"time": null,
"duration": "",
"audioName": "lion.mp3"
},
{
"type": "txt",
"audio": "https://staging-teach.cdn.ireadabc.com/fd8a2b8eeb4abbe7683d30e728ece184_l.mp3",
"text": "orange",
"image": "https://staging-teach.cdn.ireadabc.com/42aa310d755512eec187d9df73de0fd3.png",
"time": null,
"duration": "",
"audioName": "orange.mp3"
},
{
"type": "txt",
"audio": "https://staging-teach.cdn.ireadabc.com/c08af4f22c71ad8b3d8786a837787ac9_l.mp3",
"text": "hat",
"image": "https://staging-teach.cdn.ireadabc.com/9621563afaae7ac0ed01e431a11fa961.png",
"time": null,
"duration": "",
"audioName": "hat.mp3"
},
{
"type": "txt",
"audio": "https://staging-teach.cdn.ireadabc.com/f4e0925dec2f24505872b1c367343a6e_l.mp3",
"text": "noodles",
"image": "https://staging-teach.cdn.ireadabc.com/0e2058294ed4fed73a48eb4a8bfd3d37.png",
"time": null,
"duration": "",
"audioName": "noodles.mp3"
},
{
"type": "img",
"audio": "https://staging-teach.cdn.ireadabc.com/ce3337620f22232dd15c29c66af57736_l.mp3",
"text": "monkey",
"image": "https://staging-teach.cdn.ireadabc.com/340eb5c942ddfbf3fbebace4d14d4472.png",
"time": null,
"duration": "",
"audioName": "monkey.mp3"
},
{
"type": "img",
"audio": "https://staging-teach.cdn.ireadabc.com/48f94d8e04450d52c3a53554d193e92a_l.mp3",
"text": "yogurt",
"image": "https://staging-teach.cdn.ireadabc.com/42fdd3511537ee5bb55612f29f4667e2.png",
"time": null,
"duration": "",
"audioName": "yogurt.mp3"
} }
// {
// "type": "txt",
// "audio": "https://staging-teach.cdn.ireadabc.com/8d6a8d7764011afb0ef537d5a44d1d10_l.mp3",
// "text": "key",
// "image": "https://staging-teach.cdn.ireadabc.com/ab9962445d23c0df3a021ae3996412bc.png",
// "time": null,
// "duration": "",
// "audioName": "key.mp3"
// },
// {
// "type": "img",
// "audio": "https://staging-teach.cdn.ireadabc.com/e634280a803a6c9d0b0b51b41f017254_l.mp3",
// "text": "lion",
// "image": "https://staging-teach.cdn.ireadabc.com/26a3965f155e85980be316c077a93004.png",
// "time": null,
// "duration": "",
// "audioName": "lion.mp3"
// },
// {
// "type": "txt",
// "audio": "https://staging-teach.cdn.ireadabc.com/fd8a2b8eeb4abbe7683d30e728ece184_l.mp3",
// "text": "orange",
// "image": "https://staging-teach.cdn.ireadabc.com/42aa310d755512eec187d9df73de0fd3.png",
// "time": null,
// "duration": "",
// "audioName": "orange.mp3"
// },
// {
// "type": "txt",
// "audio": "https://staging-teach.cdn.ireadabc.com/c08af4f22c71ad8b3d8786a837787ac9_l.mp3",
// "text": "hat",
// "image": "https://staging-teach.cdn.ireadabc.com/9621563afaae7ac0ed01e431a11fa961.png",
// "time": null,
// "duration": "",
// "audioName": "hat.mp3"
// },
// {
// "type": "txt",
// "audio": "https://staging-teach.cdn.ireadabc.com/f4e0925dec2f24505872b1c367343a6e_l.mp3",
// "text": "noodles",
// "image": "https://staging-teach.cdn.ireadabc.com/0e2058294ed4fed73a48eb4a8bfd3d37.png",
// "time": null,
// "duration": "",
// "audioName": "noodles.mp3"
// },
// {
// "type": "img",
// "audio": "https://staging-teach.cdn.ireadabc.com/ce3337620f22232dd15c29c66af57736_l.mp3",
// "text": "monkey",
// "image": "https://staging-teach.cdn.ireadabc.com/340eb5c942ddfbf3fbebace4d14d4472.png",
// "time": null,
// "duration": "",
// "audioName": "monkey.mp3"
// },
// {
// "type": "img",
// "audio": "https://staging-teach.cdn.ireadabc.com/48f94d8e04450d52c3a53554d193e92a_l.mp3",
// "text": "yogurt",
// "image": "https://staging-teach.cdn.ireadabc.com/42fdd3511537ee5bb55612f29f4667e2.png",
// "time": null,
// "duration": "",
// "audioName": "yogurt.mp3"
// }
] ]
} }
\ No newline at end of file
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