Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SSAPP2502
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
SSAPP2502
Commits
38a3e43f
Commit
38a3e43f
authored
Aug 23, 2025
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(SSAPP2502): 优化糖果节点管理和滚动逻辑
parent
bf4e8a1c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
129 additions
and
104 deletions
+129
-104
SSAPP2502.ts
assets/SSAPP2502/scene/SSAPP2502.ts
+110
-84
defaultData.ts
assets/SSAPP2502/script/defaultData.ts
+19
-20
No files found.
assets/SSAPP2502/scene/SSAPP2502.ts
View file @
38a3e43f
...
...
@@ -349,15 +349,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
scrollDistance
=
0
;
this
.
needScroll
=
unansweredQuestions
.
length
>
4
;
// 如果有超过4个未回答题目,启用滚动
// 初始化数据队列
// 清空现有节点和待添加队列
this
.
activeNodes
=
[];
this
.
layout
.
removeAllChildren
();
this
.
pendingCandyData
=
[];
// 重置待添加队列
// 初始化显示的节点数量
// 如果剩余题目小于等于4个,显示所有剩余题目;否则显示5个
const
initialVisibleCount
=
unansweredQuestions
.
length
<=
4
?
unansweredQuestions
.
length
:
Math
.
min
(
5
,
unansweredQuestions
.
length
);
const
visibleData
=
unansweredQuestions
.
slice
(
0
,
initialVisibleCount
);
this
.
pendingCandyData
=
unansweredQuestions
.
slice
(
initialVisibleCount
);
// 清空现有节点
this
.
activeNodes
=
[];
this
.
layout
.
removeAllChildren
();
// 添加初始可见的糖果节点
visibleData
.
forEach
((
data
,
index
)
=>
{
...
...
@@ -372,34 +372,51 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
/**
* 添加新的糖果节点到布局的最后位置
* 如果待添加队列为空,会重新获取未回答的题目
* 获取界面上已显示的题目ID列表
*/
private
addNewCandyNode
()
{
// 检查是否有糖果节点模板
if
(
!
this
.
item
)
return
;
private
getDisplayedQuestionIds
():
number
[]
{
const
displayedIds
:
number
[]
=
[];
if
(
this
.
layout
&&
this
.
layout
.
childrenCount
>
0
)
{
for
(
let
i
=
0
;
i
<
this
.
layout
.
childrenCount
;
i
++
)
{
const
node
=
this
.
layout
.
children
[
i
]
as
CandyNode
;
if
(
node
.
active
&&
node
.
data
&&
node
.
data
.
id
)
{
displayedIds
.
push
(
node
.
data
.
id
);
}
}
}
return
displayedIds
;
}
// 如果待添加队列为空,重新获取未回答的题目
if
(
this
.
pendingCandyData
.
length
===
0
)
{
/**
* 更新待添加队列,只添加界面上没有显示的题目
*/
private
updatePendingCandyData
()
{
// 获取所有未回答的题目
const
unansweredQuestions
=
this
.
getUnansweredQuestions
();
// 获取界面上已显示的题目ID
const
displayedIds
=
this
.
getDisplayedQuestionIds
();
// 获取待添加队列中的题目ID
const
pendingIds
=
this
.
pendingCandyData
.
map
(
item
=>
item
.
id
);
// 如果没有未回答的题目,则不添加新节点
if
(
unansweredQuestions
.
length
===
0
)
{
this
.
needScroll
=
false
;
// 停止滚动
return
;
}
// 只添加界面上没有显示且不在待添加队列中的题目
const
newPendingData
=
unansweredQuestions
.
filter
(
question
=>
!
displayedIds
.
includes
(
question
.
id
)
&&
!
pendingIds
.
includes
(
question
.
id
)
);
// 如果未回答题目数量小于等于4,停止滚动并重新刷新列表
if
(
unansweredQuestions
.
length
<=
4
)
{
this
.
needScroll
=
false
;
// 停止滚动
// 重新显示页面
this
.
showPage
();
return
;
// 将新的题目添加到待添加队列
this
.
pendingCandyData
.
push
(...
newPendingData
);
}
// 将未回答的题目添加到待添加队列
this
.
pendingCandyData
=
unansweredQuestions
;
}
/**
* 添加新的糖果节点到布局的最后位置
* 只有当界面上没有对应题目的节点时才会添加
*/
private
addNewCandyNode
()
{
// 检查是否有糖果节点模板
if
(
!
this
.
item
)
return
;
// 更新待添加队列
this
.
updatePendingCandyData
();
// 从待添加队列中取出一个数据
const
data
=
this
.
pendingCandyData
.
shift
();
...
...
@@ -478,20 +495,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 重置无操作计时器
this
.
inactiveTimer
=
0
;
// 更新待添加的糖果数据队列,获取最新的未回答题目
// 这样在无限滚动时会排除刚刚回答正确的题目
const
unansweredQuestions
=
this
.
getUnansweredQuestions
();
this
.
pendingCandyData
=
unansweredQuestions
;
// // 如果未回答题目数量小于5,停止滚动并重新刷新列表
// if (unansweredQuestions.length < 5 && unansweredQuestions.length > 0) {
// this.needScroll = false; // 停止滚动
// // 延迟一段时间后重新显示页面
// this.scheduleOnce(() => {
// this.showPage();
// }, 0.1); // 延迟1秒,给用户时间看到当前页面的完成状态
// return;
// }
// 从待添加队列中移除已回答的题目
if
(
this
.
touchData
)
{
const
answeredQuestionId
=
this
.
touchData
.
id
;
this
.
pendingCandyData
=
this
.
pendingCandyData
.
filter
(
q
=>
q
.
id
!==
answeredQuestionId
);
}
// 在滚动列表中查找并隐藏对应题目的节点
if
(
this
.
touchData
&&
this
.
layout
&&
this
.
layout
.
childrenCount
>
0
)
{
...
...
@@ -512,13 +520,20 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
}
// 检查当前页面是否所有火苗都已处理完毕
// 更新待添加队列,确保只包含界面上没有显示的未回答题目
this
.
updatePendingCandyData
();
// 检查当前页面是否所有活跃节点都已处理完毕
if
(
this
.
activeNodes
.
length
===
0
)
{
// 延迟一段时间后检查是否需要切换到下一页
this
.
scheduleOnce
(()
=>
{
// 检查是否需要进入下一页
this
.
nextPage
();
},
1.0
);
// 延迟1秒,给用户时间看到当前页面的完成状态
// 检查是否还有未回答的题目
const
unansweredQuestions
=
this
.
getUnansweredQuestions
();
if
(
unansweredQuestions
.
length
>
0
)
{
// 还有未回答的题目,重新显示页面
// this.showPage();
}
else
{
// 所有题目都已回答完毕,游戏结束
this
.
gameOver
();
}
}
}
onRecordFail
()
{
...
...
@@ -556,27 +571,27 @@ export default class SceneComponent extends MyCocosSceneComponent {
* 在无限滚动模式下,更新未回答题目列表并重新显示页面
*/
nextPage
()
{
// 切换到下一页
Game
.
getIns
().
addPage
();
//
//
切换到下一页
//
Game.getIns().addPage();
// 获取最新的未回答题目
const
unansweredQuestions
=
this
.
getUnansweredQuestions
();
this
.
pendingCandyData
=
unansweredQuestions
;
//
//
获取最新的未回答题目
//
const unansweredQuestions = this.getUnansweredQuestions();
//
this.pendingCandyData = unansweredQuestions;
// 如果没有未回答的题目,游戏结束
if
(
unansweredQuestions
.
length
===
0
)
{
// 可以在这里添加游戏结束逻辑
this
.
gameOver
();
return
;
}
//
//
如果没有未回答的题目,游戏结束
//
if (unansweredQuestions.length === 0) {
//
// 可以在这里添加游戏结束逻辑
//
this.gameOver();
//
return;
//
}
// 如果未回答题目数量小于等于4,设置不滚动
if
(
unansweredQuestions
.
length
<=
4
)
{
this
.
needScroll
=
false
;
}
//
//
如果未回答题目数量小于等于4,设置不滚动
//
if (unansweredQuestions.length <= 4) {
//
this.needScroll = false;
//
}
// 重新显示页面
this
.
showPage
();
//
//
重新显示页面
//
this.showPage();
}
/**
...
...
@@ -887,7 +902,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
// 更新滚动状态,根据剩余未回答题目数量决定是否继续滚动
this
.
needScroll
=
this
.
activeNodes
.
length
>
4
||
this
.
pendingCandyData
.
length
>
0
;
//
this.needScroll = this.activeNodes.length > 4 || this.pendingCandyData.length > 0;
}
/**
...
...
@@ -928,20 +943,24 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 累计滚动距离
this
.
scrollDistance
=
Math
.
abs
(
this
.
layout
.
x
)
-
this
.
addCount
*
100
;
if
(
this
.
layout
.
childrenCount
<=
6
)
{
if
(
!
this
.
addCount
&&
this
.
pendingCandyData
.
length
>
0
)
{
if
(
!
this
.
addCount
)
{
this
.
addCount
=
1
;
this
.
addNewCandyNode
();
// 添加新节点
}
else
{
if
(
this
.
pendingCandyData
.
length
==
0
)
{
let
unansweredQuestions
=
this
.
getUnansweredQuestions
();
// 更新待添加队列,确保只添加界面上没有的题目
this
.
updatePendingCandyData
();
// 如果待添加队列为空,检查是否需要停止滚动
if
(
this
.
pendingCandyData
.
length
===
0
)
{
const
unansweredQuestions
=
this
.
getUnansweredQuestions
();
// 如果未回答题目数量小于等于4,停止滚动并重新刷新列表
if
(
unansweredQuestions
.
length
<=
4
)
{
this
.
needScroll
=
false
;
// 停止滚动
this
.
showPage
();
// 重新显示页面
return
;
}
this
.
pendingCandyData
=
unansweredQuestions
.
concat
();
// if (unansweredQuestions.length <= 4) {
// this.needScroll = false; // 停止滚动
// this.showPage(); // 重新显示页面
// return;
// }
}
this
.
addCount
++
;
this
.
addNewCandyNode
();
// 添加新节点
}
...
...
@@ -950,6 +969,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 检查第一个糖果节点是否已经移出视图
const
firstCandy
=
this
.
layout
.
children
[
0
];
if
(
firstCandy
&&
firstCandy
.
x
+
this
.
layout
.
x
+
firstCandy
.
width
/
2
<
0
)
{
// 获取移出画面的节点数据
const
removedNodeData
=
(
firstCandy
as
CandyNode
).
data
;
// 从活跃节点数组中移除第一个节点
if
(
this
.
activeNodes
.
includes
(
firstCandy
))
{
const
index
=
this
.
activeNodes
.
indexOf
(
firstCandy
);
...
...
@@ -962,6 +984,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
firstCandy
.
removeFromParent
();
firstCandy
.
destroy
();
// 如果移出的节点对应的题目还未回答,将其重新添加到待添加队列
if
(
removedNodeData
)
{
const
unansweredQuestions
=
this
.
getUnansweredQuestions
();
const
isStillUnanswered
=
unansweredQuestions
.
some
(
q
=>
q
.
id
===
removedNodeData
.
id
);
if
(
isStillUnanswered
&&
!
this
.
pendingCandyData
.
some
(
q
=>
q
.
id
===
removedNodeData
.
id
))
{
this
.
pendingCandyData
.
push
(
removedNodeData
);
}
}
console
.
log
(
"
当前节点数量
"
+
this
.
layout
.
childrenCount
);
}
}
...
...
@@ -1122,6 +1153,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
let
isSuccess
=
this
.
checkWords
(
data
);
this
.
log
(
"
data:
"
+
JSON
.
stringify
(
data
));
// 保存录音数据
Game
.
getIns
().
player
.
addVoice
(
data
);
// 根据评分和单词正确性显示不同的提示
if
(
isSuccess
)
{
this
.
recordTouching
=
false
;
...
...
@@ -1131,20 +1164,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 80分及以上,显示优秀提示(3星)
this
.
updateTips
(
TIPS_STATE
.
EXCELLENT
);
pg
.
hw
.
playLocalAudio
(
'
score_success
'
);
// 保存录音数据
Game
.
getIns
().
player
.
addVoice
(
data
);
}
else
if
(
score
>=
60
)
{
// 60-80分,显示不错提示(2星)
this
.
updateTips
(
TIPS_STATE
.
NICE
);
pg
.
hw
.
playLocalAudio
(
'
score_success
'
);
// 保存录音数据
Game
.
getIns
().
player
.
addVoice
(
data
);
}
else
if
(
score
>=
10
)
{
// 10-60分,显示加油提示(1星)
this
.
updateTips
(
TIPS_STATE
.
COMEON
);
pg
.
hw
.
playLocalAudio
(
'
score_success
'
);
// 保存录音数据
Game
.
getIns
().
player
.
addVoice
(
data
);
}
else
{
// 10分以下,显示再试一次提示(0星)
this
.
updateTips
(
TIPS_STATE
.
TRYAGAIN
);
...
...
@@ -1173,7 +1200,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
if
(
this
.
touchData
&&
this
.
touchData
.
parent
&&
!
this
.
activeNodes
.
includes
(
this
.
touchData
.
parent
))
{
this
.
activeNodes
.
push
(
this
.
touchData
.
parent
);
}
Game
.
getIns
().
player
.
addVoice
(
data
);
}
// 延迟后隐藏提示
...
...
assets/SSAPP2502/script/defaultData.ts
View file @
38a3e43f
...
...
@@ -26,25 +26,24 @@ export const defaultData = {
"
duration
"
:
30
,
"
audioName
"
:
"
shoot.MP3
"
},
// {
// "type": "img",
// "audio": "http://staging-teach.cdn.ireadabc.com/a6fb6452f0e383808cd056939ed81917_l.mp3", "text": "circle", "image": "http://staging-teach.cdn.ireadabc.com/d0652838333e892b5e495fbdd8746fa0.png",
// "time": null, "duration": 30,
// "audioName": "levelup.MP3"
// }, {
// "type": "txt",
// "audio": "http://staging-teach.cdn.ireadabc.com/e8d058205a1bc894c55a9dc46d60717f_l.mp3", "text": "shoot", "image": "",
// "time": null, "duration": 30,
// "audioName": "yasuo.mp3"
// }, {
// "type": "txt", "audio": "", "text": "apple", "image": "", "time": null, "duration": 30, "audioName": ""
// }, {
// "type": "txt", "audio": "", "text": "international", "image": "", "time": null, "duration": 30, "audioName": ""
// }, {
// "type": "txt", "audio": "", "text": "deep", "image": "", "time": null, "duration": 30, "audioName": ""
// }, {
// "type": "txt", "audio": "", "text": "fun", "image": "", "time": null, "duration": 10, "audioName": ""
// }
{
"
type
"
:
"
img
"
,
"
audio
"
:
"
http://staging-teach.cdn.ireadabc.com/a6fb6452f0e383808cd056939ed81917_l.mp3
"
,
"
text
"
:
"
circle
"
,
"
image
"
:
"
http://staging-teach.cdn.ireadabc.com/d0652838333e892b5e495fbdd8746fa0.png
"
,
"
time
"
:
null
,
"
duration
"
:
30
,
"
audioName
"
:
"
levelup.MP3
"
},
{
"
type
"
:
"
txt
"
,
"
audio
"
:
"
http://staging-teach.cdn.ireadabc.com/e8d058205a1bc894c55a9dc46d60717f_l.mp3
"
,
"
text
"
:
"
shoot
"
,
"
image
"
:
""
,
"
time
"
:
null
,
"
duration
"
:
30
,
"
audioName
"
:
"
yasuo.mp3
"
},
{
"
type
"
:
"
txt
"
,
"
audio
"
:
""
,
"
text
"
:
"
apple
"
,
"
image
"
:
""
,
"
time
"
:
null
,
"
duration
"
:
30
,
"
audioName
"
:
""
},
{
"
type
"
:
"
txt
"
,
"
audio
"
:
""
,
"
text
"
:
"
international
"
,
"
image
"
:
""
,
"
time
"
:
null
,
"
duration
"
:
30
,
"
audioName
"
:
""
},
{
"
type
"
:
"
txt
"
,
"
audio
"
:
""
,
"
text
"
:
"
deep
"
,
"
image
"
:
""
,
"
time
"
:
null
,
"
duration
"
:
30
,
"
audioName
"
:
""
},
{
"
type
"
:
"
txt
"
,
"
audio
"
:
""
,
"
text
"
:
"
fun
"
,
"
image
"
:
""
,
"
time
"
:
null
,
"
duration
"
:
10
,
"
audioName
"
:
""
}
]
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment