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
839d7efc
Commit
839d7efc
authored
Aug 25, 2025
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(SSAPP2502): 优化糖果节点布局逻辑并更新默认数据
parent
b85c0295
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
145 deletions
+107
-145
SSAPP2502.ts
assets/SSAPP2502/scene/SSAPP2502.ts
+51
-114
defaultData.ts
assets/SSAPP2502/script/defaultData.ts
+56
-31
No files found.
assets/SSAPP2502/scene/SSAPP2502.ts
View file @
839d7efc
...
...
@@ -174,8 +174,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
private
needScroll
:
boolean
=
false
;
/** 糖果节点宽度 */
private
candyNodeWidth
:
number
=
0
;
/** 待添加的糖果数据队列 */
private
pendingCandyData
:
Option
[]
=
[];
/** 滚动距离累计 */
private
scrollDistance
:
number
=
0
;
// 移除了提示动画相关的变量
...
...
@@ -290,12 +288,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
* @param data 节点数据
* @param index 题目在数组中的索引,用于确定显示哪个糖果图标
*/
updateItem
(
candyNode
:
CandyNode
,
data
:
Option
,
index
:
number
=
0
)
{
updateItem
(
candyNode
:
CandyNode
,
data
:
Option
,
x
:
number
)
{
// 设置基本属性
candyNode
.
data
=
data
;
candyNode
.
active
=
true
;
candyNode
.
y
=
0
;
candyNode
.
x
=
index
*
320
+
150
;
candyNode
.
x
=
x
;
// 获取子节点
const
iconNode
=
candyNode
.
getChildByName
(
'
icon
'
);
const
bgFullNode
=
candyNode
.
getChildByName
(
'
bg_full
'
);
...
...
@@ -308,7 +306,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 根据索引设置糖果图标(candy_0 ~ candy_4)
if
(
iconNode
)
{
// 确保索引在有效范围内(0-4)
const
candyIndex
=
index
%
5
;
const
candyIndex
=
data
.
id
%
5
;
const
candyIconName
=
`candy_
${
candyIndex
}
`
;
// 使用pg.view.setImg加载对应的糖果图标
...
...
@@ -352,18 +350,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 清空现有节点和待添加队列
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
);
// 添加初始可见的糖果节点
visibleData
.
forEach
((
data
,
index
)
=>
{
unansweredQuestions
.
forEach
((
data
,
index
)
=>
{
const
candyNode
=
cc
.
instantiate
(
this
.
item
)
as
CandyNode
;
this
.
layout
.
addChild
(
candyNode
);
this
.
updateItem
(
candyNode
,
data
,
index
);
this
.
updateItem
(
candyNode
,
data
,
index
*
320
+
150
);
if
(
index
===
0
)
{
this
.
candyNodeWidth
=
candyNode
.
width
;
}
...
...
@@ -379,7 +371,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
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
)
{
if
(
node
.
active
&&
node
.
data
&&
(
node
.
data
.
id
||
node
.
data
.
id
==
0
)
)
{
displayedIds
.
push
(
node
.
data
.
id
);
}
}
...
...
@@ -387,52 +379,31 @@ export default class SceneComponent extends MyCocosSceneComponent {
return
displayedIds
;
}
/**
* 更新待添加队列,只添加界面上没有显示的题目
*/
private
updatePendingCandyData
()
{
// 获取所有未回答的题目
const
unansweredQuestions
=
this
.
getUnansweredQuestions
();
// 获取界面上已显示的题目ID
const
displayedIds
=
this
.
getDisplayedQuestionIds
();
// 获取待添加队列中的题目ID
const
pendingIds
=
this
.
pendingCandyData
.
map
(
item
=>
item
.
id
);
// 只添加界面上没有显示且不在待添加队列中的题目
const
newPendingData
=
unansweredQuestions
.
filter
(
question
=>
!
displayedIds
.
includes
(
question
.
id
)
&&
!
pendingIds
.
includes
(
question
.
id
)
);
// 将新的题目添加到待添加队列
this
.
pendingCandyData
.
push
(...
newPendingData
);
}
/**
* 添加新的糖果节点到布局的最后位置
* 只有当界面上没有对应题目的节点时才会添加
*/
private
addNewCandyNode
()
{
// 检查是否有糖果节点模板
if
(
!
this
.
item
)
return
;
// 更新待添加队列
this
.
updatePendingCandyData
();
// 从待添加队列中取出一个数据
const
data
=
this
.
pendingCandyData
.
shift
();
if
(
!
data
)
return
;
// 创建新的糖果节点
const
candyNode
=
cc
.
instantiate
(
this
.
item
)
as
CandyNode
;
this
.
layout
.
addChild
(
candyNode
);
this
.
updateItem
(
candyNode
,
data
,
this
.
addCount
+
4
);
this
.
activeNodes
.
push
(
candyNode
);
// 如果有足够的节点,启用滚动
if
(
this
.
activeNodes
.
length
>
4
)
{
this
.
needScroll
=
true
;
}
}
// private lastid: number = 0;
// private addNewCandyNode() {
// // 检查是否有糖果节点模板
// if (!this.item) return;
// // 从待添加队列中取出一个数据
// const data = this.pendingCandyData.shift();
// if (!data) return;
// const displayedIds = this.getDisplayedQuestionIds();
// if (displayedIds.includes(data.id)) return;
// // 创建新的糖果节点
// const candyNode = cc.instantiate(this.item) as CandyNode;
// this.layout.addChild(candyNode);
// this.updateItem(candyNode, data);
// this.activeNodes.push(candyNode);
// // 如果有足够的节点,启用滚动
// if (this.activeNodes.length > 4) {
// this.needScroll = true;
// }
// }
/**
* 火苗点击事件处理
* 保存触摸数据并显示卡片
...
...
@@ -496,10 +467,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
inactiveTimer
=
0
;
// 从待添加队列中移除已回答的题目
if
(
this
.
touchData
)
{
const
answeredQuestionId
=
this
.
touchData
.
id
;
this
.
pendingCandyData
=
this
.
pendingCandyData
.
filter
(
q
=>
q
.
id
!==
answeredQuestionId
);
}
//
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
)
{
...
...
@@ -520,8 +491,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
}
// 更新待添加队列,确保只包含界面上没有显示的未回答题目
this
.
updatePendingCandyData
();
// 检查当前页面是否所有活跃节点都已处理完毕
if
(
this
.
activeNodes
.
length
===
0
)
{
...
...
@@ -942,58 +911,26 @@ 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
.
addCount
=
1
;
this
.
addNewCandyNode
();
// 添加新节点
}
else
{
// 更新待添加队列,确保只添加界面上没有的题目
this
.
updatePendingCandyData
();
// 如果待添加队列为空,检查是否需要停止滚动
if
(
this
.
pendingCandyData
.
length
===
0
)
{
const
unansweredQuestions
=
this
.
getUnansweredQuestions
();
// 如果未回答题目数量小于等于4,停止滚动并重新刷新列表
// if (unansweredQuestions.length <= 4) {
// this.needScroll = false; // 停止滚动
// this.showPage(); // 重新显示页面
// return;
// }
}
this
.
addCount
++
;
this
.
addNewCandyNode
();
// 添加新节点
this
.
checkRemoveNode
();
}
}
/**
* 检查并移除移出视图的节点
*/
private
checkRemoveNode
()
{
// 检查第一个糖果节点是否已经移出视图
const
firstCandy
=
this
.
layout
.
children
[
0
];
const
children
=
this
.
layout
.
children
.
concat
();
children
.
sort
((
A
,
B
)
=>
A
.
x
-
B
.
x
);
const
firstCandy
=
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
);
if
(
index
!==
-
1
)
{
this
.
activeNodes
.
splice
(
index
,
1
);
}
}
// 从布局中移除第一个节点
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
);
if
(
firstCandy
)
{
const
x
=
children
[
children
.
length
-
1
].
x
+
320
;
firstCandy
.
x
=
x
;
}
}
}
...
...
assets/SSAPP2502/script/defaultData.ts
View file @
839d7efc
...
...
@@ -8,42 +8,67 @@
* @description 默认游戏数据对象,包含游戏的基本配置和问题数据
* @type {Object}
*/
export
const
defaultData
=
{
"
score
"
:
0
,
"
title
"
:
""
,
"
questionText
"
:
""
,
"
questionType
"
:
"
read
"
,
"
questionTextAudio
"
:
""
,
"
bgAudio
"
:
""
,
"
questions
"
:
[
export
const
defaultData
=
{
"
score
"
:
0
,
"
title
"
:
""
,
"
questionText
"
:
""
,
"
questionType
"
:
"
read
"
,
"
questionTextAudio
"
:
""
,
"
bgAudio
"
:
""
,
"
questions
"
:
[
{
"
type
"
:
"
img
"
,
"
audio
"
:
"
http
://staging-teach.cdn.ireadabc.com/ae2538a7ef5de1b4836a882d625271af
_l.mp3
"
,
"
text
"
:
"
left
"
,
"
image
"
:
"
http
://staging-teach.cdn.ireadabc.com/41b95f47d23e0712f825eec9e718caed
.png
"
,
"
audio
"
:
"
http
s://staging-teach.cdn.ireadabc.com/a6a5c388c636bc6d063946e91b4bd21a
_l.mp3
"
,
"
text
"
:
"
egg
"
,
"
image
"
:
"
http
s://staging-teach.cdn.ireadabc.com/7b315ba7227294d63933cd659d5372fb
.png
"
,
"
time
"
:
null
,
"
duration
"
:
30
,
"
audioName
"
:
"
heal_money.mp3
"
},
{
"
duration
"
:
""
,
"
audioName
"
:
"
egg.mp3
"
},
{
"
type
"
:
"
img
"
,
"
audio
"
:
"
http://staging-teach.cdn.ireadabc.com/4f3bb8f8fa048f40c1bb5d6d2f6d9a33_l.mp3
"
,
"
text
"
:
"
down
"
,
"
image
"
:
"
http://staging-teach.cdn.ireadabc.com/fbe3d792ce2a72310e5298e1d75d0d71.png
"
,
"
time
"
:
null
,
"
duration
"
:
30
,
"
audioName
"
:
"
shoot.MP3
"
"
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/e634280a803a6c9d0b0b51b41f017254_l.mp3
"
,
"
text
"
:
"
lion
"
,
"
image
"
:
""
,
"
time
"
:
null
,
"
duration
"
:
""
,
"
audioName
"
:
"
lion.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
"
},
{
"
audio
"
:
"
https://staging-teach.cdn.ireadabc.com/c0926db86deeb3edc9642cb14a516b36_l.mp3
"
,
"
text
"
:
"
horse
"
,
"
image
"
:
"
https://staging-teach.cdn.ireadabc.com/40384ac2d06139da212c1f0abf9217c4.png
"
,
"
time
"
:
null
,
"
duration
"
:
""
,
"
audioName
"
:
"
zebra.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
"
:
"
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
"
:
""
"
audio
"
:
"
https://staging-teach.cdn.ireadabc.com/dea81adc2abe8e7849df33bc952900bc_l.mp3
"
,
"
text
"
:
"
rabbit
"
,
"
image
"
:
""
,
"
time
"
:
null
,
"
duration
"
:
""
,
"
audioName
"
:
"
rabbit.mp3
"
}
]
}
\ No newline at end of file
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