Commit 3fd50703 authored by Tt's avatar Tt

1

parent 127b7fa0
...@@ -264,12 +264,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -264,12 +264,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
const bgBrokenNode = candyNode.getChildByName('bg_broken'); const bgBrokenNode = candyNode.getChildByName('bg_broken');
// 设置背景状态:默认显示bg_full,隐藏bg_broken // 设置背景状态:默认显示bg_full,隐藏bg_broken
if (bgFullNode) { pg.view.visible(bgFullNode, true);
bgFullNode.active = true; pg.view.visible(bgBrokenNode, false);
}
if (bgBrokenNode) {
bgBrokenNode.active = false;
}
// 根据索引设置糖果图标(candy_0 ~ candy_4) // 根据索引设置糖果图标(candy_0 ~ candy_4)
if (iconNode) { if (iconNode) {
...@@ -293,10 +289,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -293,10 +289,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
* 添加了糖果区域滚动逻辑 * 添加了糖果区域滚动逻辑
*/ */
showPage() { showPage() {
// 获取当前页码
const currentPage = Game.getIns().getCurrentPageNum();
const prevPage = currentPage - 1;
// 获取当前页的数据 // 获取当前页的数据
const pageData = Game.getIns().getPageData(); const pageData = Game.getIns().getPageData();
...@@ -305,58 +297,22 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -305,58 +297,22 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.needScroll = false; this.needScroll = false;
this.pendingCandyData = []; this.pendingCandyData = [];
// 清空活跃火苗节点数组
this.activeFireNodes = []; this.activeFireNodes = [];
// 清空糖果区域
this.layout.removeAllChildren(); this.layout.removeAllChildren();
// 根据当前数据,将糖果节点克隆到糖果区域 const len = 5;
if (pageData && pageData.length > 0) { this.needScroll = true;
// 确定是否需要滚动 const visibleData = pageData.slice(0, len);
const len = 10; this.pendingCandyData = pageData.slice(len);
if (pageData.length > len) { visibleData.forEach((data, index) => {
this.needScroll = true; const candyNode = cc.instantiate(this.item) as CandyNode;
// 将前5个数据显示在屏幕上,其余放入待添加队列 this.layout.addChild(candyNode);
const visibleData = pageData.slice(0, len); this.updateItem(candyNode, data, index);
this.pendingCandyData = pageData.slice(len); if (index === 0) {
this.candyNodeWidth = candyNode.width;
// 遍历可见数据
visibleData.forEach((data, index) => {
// 克隆糖果节点
const candyNode = cc.instantiate(this.item) as CandyNode;
// 使用updateItem方法更新节点内容,传入索引以显示对应的糖果图标
this.updateItem(candyNode, data, index);
// 记录糖果节点宽度(用于滚动计算)
if (index === 0) {
this.candyNodeWidth = candyNode.width;
}
// 将糖果节点添加到活跃火苗节点数组
this.activeFireNodes.push(candyNode);
// 将糖果节点添加到糖果区域
this.layout.addChild(candyNode);
});
} else {
// 数量不超过5个,正常显示所有节点
pageData.forEach((data, index) => {
// 克隆糖果节点
const candyNode = cc.instantiate(this.item) as CandyNode;
// 使用updateItem方法更新节点内容,传入索引以显示对应的糖果图标
this.updateItem(candyNode, data, index);
// 将糖果节点添加到活跃火苗节点数组
this.activeFireNodes.push(candyNode);
// 将糖果节点添加到糖果区域
this.layout.addChild(candyNode);
});
} }
} this.activeFireNodes.push(candyNode);
});
} }
/** /**
......
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