Commit a9cc2e7d authored by Tt's avatar Tt

feat(游戏场景): 添加游戏重启功能及相关UI

parent db60e65e
...@@ -94,18 +94,24 @@ ...@@ -94,18 +94,24 @@
}, },
{ {
"__id__": 175 "__id__": 175
},
{
"__id__": 183
},
{
"__id__": 184
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 200 "__id__": 209
}, },
{ {
"__id__": 201 "__id__": 210
}, },
{ {
"__id__": 202 "__id__": 211
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -8609,7 +8615,7 @@ ...@@ -8609,7 +8615,7 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "RabbonBase", "_name": "layout_restart",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 2 "__id__": 2
...@@ -8618,12 +8624,388 @@ ...@@ -8618,12 +8624,388 @@
{ {
"__id__": 176 "__id__": 176
}, },
{
"__id__": 180
}
],
"_active": false,
"_components": [
{
"__id__": 182
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 1920,
"height": 1080
},
"_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": "13Au7QMxZHxpdNswpeBGbn"
},
{
"__type__": "cc.Node",
"_name": "gray",
"_objFlags": 0,
"_parent": {
"__id__": 175
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 177
},
{
"__id__": 178
},
{ {
"__id__": 179 "__id__": 179
}
],
"_prefab": null,
"_opacity": 150,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 1920,
"height": 1080
},
"_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": "e1z3Kwru5AZZy+jrtnK/eE"
}, },
{ {
"__id__": 182 "__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 176
}, },
"_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": "48TDR9NDdNTKBDVIczcVxK"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 176
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 45,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 100,
"_originalHeight": 100,
"_id": "d6mN6CsLtLpI8vXvchzqgG"
},
{
"__type__": "cc.BlockInputEvents",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 176
},
"_enabled": true,
"_id": "e9hSVu33ZJQYS+dyACV4YA"
},
{
"__type__": "cc.Node",
"_name": "btn_restart",
"_objFlags": 0,
"_parent": {
"__id__": 175
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 181
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 407,
"height": 179
},
"_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": "4dOvqMRdVO36GB+6dstMcp"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 180
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": {
"__uuid__": "d7580966-b781-4363-99e0-617bb3bfdd48"
},
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": "ec0D5DB+NK76QEvHFdXP/0"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 175
},
"_enabled": true,
"alignMode": 1,
"_target": null,
"_alignFlags": 45,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_verticalCenter": 0,
"_horizontalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_id": "2blcZv3RJGSbNAnuq2aYwE"
},
{
"__type__": "cc.Node",
"_name": "ani",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_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": "e6yLbrZglImrxTuAoAHWfm"
},
{
"__type__": "cc.Node",
"_name": "RabbonBase",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [
{ {
"__id__": 185 "__id__": 185
}, },
...@@ -8638,6 +9020,15 @@ ...@@ -8638,6 +9020,15 @@
}, },
{ {
"__id__": 197 "__id__": 197
},
{
"__id__": 200
},
{
"__id__": 203
},
{
"__id__": 206
} }
], ],
"_active": true, "_active": true,
...@@ -8695,11 +9086,11 @@ ...@@ -8695,11 +9086,11 @@
"_name": "New Node", "_name": "New Node",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 175 "__id__": 184
}, },
"_children": [ "_children": [
{ {
"__id__": 177 "__id__": 186
} }
], ],
"_active": true, "_active": true,
...@@ -8757,13 +9148,13 @@ ...@@ -8757,13 +9148,13 @@
"_name": "New Sprite", "_name": "New Sprite",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 176 "__id__": 185
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 178 "__id__": 187
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -8819,7 +9210,7 @@ ...@@ -8819,7 +9210,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 177 "__id__": 186
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -8851,11 +9242,11 @@ ...@@ -8851,11 +9242,11 @@
"_name": "New Node", "_name": "New Node",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 175 "__id__": 184
}, },
"_children": [ "_children": [
{ {
"__id__": 180 "__id__": 189
} }
], ],
"_active": true, "_active": true,
...@@ -8913,13 +9304,13 @@ ...@@ -8913,13 +9304,13 @@
"_name": "New Sprite", "_name": "New Sprite",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 179 "__id__": 188
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 181 "__id__": 190
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -8975,7 +9366,7 @@ ...@@ -8975,7 +9366,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 180 "__id__": 189
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -9007,11 +9398,11 @@ ...@@ -9007,11 +9398,11 @@
"_name": "New Node", "_name": "New Node",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 175 "__id__": 184
}, },
"_children": [ "_children": [
{ {
"__id__": 183 "__id__": 192
} }
], ],
"_active": true, "_active": true,
...@@ -9069,13 +9460,13 @@ ...@@ -9069,13 +9460,13 @@
"_name": "New Sprite", "_name": "New Sprite",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 182 "__id__": 191
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 184 "__id__": 193
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -9131,7 +9522,7 @@ ...@@ -9131,7 +9522,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 183 "__id__": 192
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -9163,11 +9554,11 @@ ...@@ -9163,11 +9554,11 @@
"_name": "New Node", "_name": "New Node",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 175 "__id__": 184
}, },
"_children": [ "_children": [
{ {
"__id__": 186 "__id__": 195
} }
], ],
"_active": true, "_active": true,
...@@ -9225,13 +9616,13 @@ ...@@ -9225,13 +9616,13 @@
"_name": "New Sprite", "_name": "New Sprite",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 185 "__id__": 194
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 187 "__id__": 196
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -9287,7 +9678,7 @@ ...@@ -9287,7 +9678,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 186 "__id__": 195
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -9319,11 +9710,11 @@ ...@@ -9319,11 +9710,11 @@
"_name": "New Node", "_name": "New Node",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 175 "__id__": 184
}, },
"_children": [ "_children": [
{ {
"__id__": 189 "__id__": 198
} }
], ],
"_active": true, "_active": true,
...@@ -9381,13 +9772,13 @@ ...@@ -9381,13 +9772,13 @@
"_name": "New Sprite", "_name": "New Sprite",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 188 "__id__": 197
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 190 "__id__": 199
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -9443,7 +9834,7 @@ ...@@ -9443,7 +9834,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 189 "__id__": 198
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -9475,11 +9866,11 @@ ...@@ -9475,11 +9866,11 @@
"_name": "New Node", "_name": "New Node",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 175 "__id__": 184
}, },
"_children": [ "_children": [
{ {
"__id__": 192 "__id__": 201
} }
], ],
"_active": true, "_active": true,
...@@ -9537,13 +9928,13 @@ ...@@ -9537,13 +9928,13 @@
"_name": "New Sprite", "_name": "New Sprite",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 191 "__id__": 200
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 193 "__id__": 202
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -9599,7 +9990,7 @@ ...@@ -9599,7 +9990,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 192 "__id__": 201
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -9631,11 +10022,11 @@ ...@@ -9631,11 +10022,11 @@
"_name": "New Node", "_name": "New Node",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 175 "__id__": 184
}, },
"_children": [ "_children": [
{ {
"__id__": 195 "__id__": 204
} }
], ],
"_active": true, "_active": true,
...@@ -9693,13 +10084,13 @@ ...@@ -9693,13 +10084,13 @@
"_name": "New Sprite", "_name": "New Sprite",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 194 "__id__": 203
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 196 "__id__": 205
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -9755,7 +10146,7 @@ ...@@ -9755,7 +10146,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 195 "__id__": 204
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
...@@ -9787,11 +10178,11 @@ ...@@ -9787,11 +10178,11 @@
"_name": "New Node", "_name": "New Node",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 175 "__id__": 184
}, },
"_children": [ "_children": [
{ {
"__id__": 198 "__id__": 207
} }
], ],
"_active": true, "_active": true,
...@@ -9849,13 +10240,13 @@ ...@@ -9849,13 +10240,13 @@
"_name": "New Sprite", "_name": "New Sprite",
"_objFlags": 0, "_objFlags": 0,
"_parent": { "_parent": {
"__id__": 197 "__id__": 206
}, },
"_children": [], "_children": [],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 199 "__id__": 208
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -9911,7 +10302,7 @@ ...@@ -9911,7 +10302,7 @@
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
"__id__": 198 "__id__": 207
}, },
"_enabled": true, "_enabled": true,
"_materials": [ "_materials": [
......
...@@ -104,6 +104,12 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -104,6 +104,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.initEvent(); // 初始化事件 this.initEvent(); // 初始化事件
this.initGame(); this.initGame();
} }
restartGame() {
this.initData(); // 初始化数据
this.initView(); // 初始化视图
this.initEvent(); // 初始化事件
this.initGame();
}
/** /**
* 组件销毁时的回调 * 组件销毁时的回调
* 清理事件监听,防止内存泄漏 * 清理事件监听,防止内存泄漏
...@@ -176,6 +182,45 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -176,6 +182,45 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.activeFireNodes = []; this.activeFireNodes = [];
// 初始化触摸状态 // 初始化触摸状态
this.touching = false; this.touching = false;
// 初始化录音相关变量
this.recordStartTime = 0;
this.maxRecordDuration = 30;
// 初始化提示相关变量
this.inactiveTimer = 0;
this.hintThreshold = 3;
this.isHintAnimPlaying = false;
// 初始化音频ID
this.audioId = -1;
// 初始化语音动画定时器
this._voiceAniTimer = null;
// 初始化语音关闭状态
this.onTouchSpeakCloseClosing = false;
// 初始化重试状态
this.tryAgain = false;
this.recordTouching = false;
// 初始化重新开始布局
this.layout_restart = null;
// 重置游戏布局和页面节点到初始状态
if (this.layout_game) {
// 重置游戏布局位置到初始状态(x=0)
this.layout_game.x = 0;
}
// 重置页面节点状态
if (this.page_a) {
this.page_a.active = true;
}
if (this.page_b) {
this.page_b.active = false;
}
} }
/** 音频播放ID */ /** 音频播放ID */
private audioId: any; private audioId: any;
...@@ -202,6 +247,13 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -202,6 +247,13 @@ 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;
const otherPageNode = currentPage % 2 === 0 ? this.page_b : this.page_a;
currentPageNode.x = 0;
otherPageNode.x = 1920;
} }
/** /**
* 初始化事件监听 * 初始化事件监听
...@@ -344,6 +396,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -344,6 +396,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 使用cc.tween实现layout_game向左移动一页的距离(1920) // 使用cc.tween实现layout_game向左移动一页的距离(1920)
cc.tween(this.layout_game) cc.tween(this.layout_game)
.to(3.0, { x: -1920 * currentPage }, { easing: 'cubicOut' }) .to(3.0, { x: -1920 * currentPage }, { easing: 'cubicOut' })
.call(() => {
otherPageNode.x = 1920 * (currentPage + 1);
})
.start(); .start();
cc.tween(this.node_firetruck) cc.tween(this.node_firetruck)
.to(3.0, { x: -400 + 1920 * currentPage }, { easing: 'cubicOut' }) .to(3.0, { x: -400 + 1920 * currentPage }, { easing: 'cubicOut' })
...@@ -1245,6 +1300,21 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1245,6 +1300,21 @@ export default class SceneComponent extends MyCocosSceneComponent {
onHomeworkFinish(data) onHomeworkFinish(data)
// 显示重新开始 // 显示重新开始
this.showRestart();
}
private layout_restart: cc.Node = null;
showRestart() {
if (!this.layout_restart) this.layout_restart = cc.find('Canvas/layout_restart');
this.layout_restart.active = true;
pg.view.touchOn(pg.view.find(this.layout_restart, 'btn_restart'), this.onTouchRestart, this);
}
hideRestart() {
if (!this.layout_restart) this.layout_restart = cc.find('Canvas/layout_restart');
this.layout_restart.active = false;
}
onTouchRestart() {
this.hideRestart();
this.restartGame();
} }
/** /**
......
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