Commit 127b7fa0 authored by Tt's avatar Tt

处理结束

parent 53d83a1e
...@@ -260,10 +260,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -260,10 +260,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
candyNode.x = index * 320 + 150; candyNode.x = index * 320 + 150;
// 获取子节点 // 获取子节点
const iconNode = candyNode.getChildByName('icon'); const iconNode = candyNode.getChildByName('icon');
const labelNode = candyNode.getChildByName('label');
const bgFullNode = candyNode.getChildByName('bg_full'); const bgFullNode = candyNode.getChildByName('bg_full');
const bgBrokenNode = candyNode.getChildByName('bg_broken'); const bgBrokenNode = candyNode.getChildByName('bg_broken');
// 设置背景状态:默认显示bg_full,隐藏bg_broken // 设置背景状态:默认显示bg_full,隐藏bg_broken
if (bgFullNode) { if (bgFullNode) {
bgFullNode.active = true; bgFullNode.active = true;
...@@ -271,43 +270,22 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -271,43 +270,22 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (bgBrokenNode) { if (bgBrokenNode) {
bgBrokenNode.active = false; bgBrokenNode.active = false;
} }
// 根据索引设置糖果图标(candy_0 ~ candy_4) // 根据索引设置糖果图标(candy_0 ~ candy_4)
if (iconNode) { if (iconNode) {
// 确保索引在有效范围内(0-4) // 确保索引在有效范围内(0-4)
const candyIndex = Math.min(Math.max(index, 0), 4); const candyIndex = index % 5;
const candyIconName = `candy_${candyIndex}`; const candyIconName = `candy_${candyIndex}`;
// 使用pg.view.setImg加载对应的糖果图标 // 使用pg.view.setImg加载对应的糖果图标
pg.view.setImg(iconNode, candyIconName); pg.view.setNodeImg(iconNode, pg.view.find(this, `res/img/${candyIconName}`));
iconNode.active = true; iconNode.active = true;
} }
// 根据数据类型设置显示内容
if (data.type === 'img' && data.picUrl) {
// 如果有图片URL,使用网络图片
if (iconNode) {
pg.view.setNetImg(iconNode, data.picUrl, { w: 200, h: 200 });
iconNode.active = true;
}
if (labelNode) {
labelNode.active = false;
}
} else if (data.txt) {
// 显示文本,保持图标显示
if (labelNode) {
pg.view.setString(labelNode, data.txt);
labelNode.active = true;
}
}
// 添加点击事件(如果节点上没有该事件) // 添加点击事件(如果节点上没有该事件)
if (!candyNode.hasEventListener(cc.Node.EventType.TOUCH_END)) { pg.view.touchOn(candyNode, this.onTouchFireNode, this);
candyNode.on(cc.Node.EventType.TOUCH_END, this.onTouchFireNode, this);
}
} }
/** /**
* 显示当前页面 * 显示当前页面
* 移除了与页面a和页面b相关的逻辑 * 移除了与页面a和页面b相关的逻辑
...@@ -336,20 +314,21 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -336,20 +314,21 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 根据当前数据,将糖果节点克隆到糖果区域 // 根据当前数据,将糖果节点克隆到糖果区域
if (pageData && pageData.length > 0) { if (pageData && pageData.length > 0) {
// 确定是否需要滚动 // 确定是否需要滚动
if (pageData.length > 5) { const len = 10;
if (pageData.length > len) {
this.needScroll = true; this.needScroll = true;
// 将前5个数据显示在屏幕上,其余放入待添加队列 // 将前5个数据显示在屏幕上,其余放入待添加队列
const visibleData = pageData.slice(0, 5); const visibleData = pageData.slice(0, len);
this.pendingCandyData = pageData.slice(5); this.pendingCandyData = pageData.slice(len);
// 遍历可见数据 // 遍历可见数据
visibleData.forEach((data, index) => { visibleData.forEach((data, index) => {
// 克隆糖果节点 // 克隆糖果节点
const candyNode = cc.instantiate(this.item) as CandyNode; const candyNode = cc.instantiate(this.item) as CandyNode;
// 使用updateItem方法更新节点内容,传入索引以显示对应的糖果图标 // 使用updateItem方法更新节点内容,传入索引以显示对应的糖果图标
this.updateItem(candyNode, data, index); this.updateItem(candyNode, data, index);
// 记录糖果节点宽度(用于滚动计算) // 记录糖果节点宽度(用于滚动计算)
if (index === 0) { if (index === 0) {
this.candyNodeWidth = candyNode.width; this.candyNodeWidth = candyNode.width;
...@@ -366,7 +345,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -366,7 +345,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
pageData.forEach((data, index) => { pageData.forEach((data, index) => {
// 克隆糖果节点 // 克隆糖果节点
const candyNode = cc.instantiate(this.item) as CandyNode; const candyNode = cc.instantiate(this.item) as CandyNode;
// 使用updateItem方法更新节点内容,传入索引以显示对应的糖果图标 // 使用updateItem方法更新节点内容,传入索引以显示对应的糖果图标
this.updateItem(candyNode, data, index); this.updateItem(candyNode, data, index);
...@@ -379,34 +358,19 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -379,34 +358,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
} }
} }
/** /**
* 添加新的糖果节点到布局的最后位置 * 添加新的糖果节点到布局的最后位置
*/ */
private addNewCandyNode() { private addNewCandyNode() {
if (this.pendingCandyData.length === 0 || !this.item) return; if (this.pendingCandyData.length === 0 || !this.item) return;
// 获取待添加的第一个数据
const data = this.pendingCandyData.shift(); const data = this.pendingCandyData.shift();
// 克隆糖果节点
const candyNode = cc.instantiate(this.item) as CandyNode; const candyNode = cc.instantiate(this.item) as CandyNode;
this.layout.addChild(candyNode);
// 使用updateItem方法更新节点内容
// 使用当前显示的节点数量作为索引
const index = this.layout.childrenCount; const index = this.layout.childrenCount;
this.updateItem(candyNode, data, index); this.updateItem(candyNode, data, index);
// 将新节点放在布局的最后位置
this.layout.addChild(candyNode);
// 将糖果节点添加到活跃火苗节点数组
this.activeFireNodes.push(candyNode); this.activeFireNodes.push(candyNode);
} }
/**
* 移除了消防车点击事件处理方法
*/
/** /**
* 火苗点击事件处理 * 火苗点击事件处理
* 保存触摸数据并显示卡片 * 保存触摸数据并显示卡片
...@@ -430,18 +394,18 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -430,18 +394,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
onFireSuccess() { onFireSuccess() {
const fireNode = this.currentFireNode; const fireNode = this.currentFireNode;
// 更新糖果背景状态:隐藏bg_full,显示bg_broken // 更新糖果背景状态:隐藏bg_full,显示bg_broken
const bgFullNode = fireNode.getChildByName('bg_full'); const bgFullNode = fireNode.getChildByName('bg_full');
const bgBrokenNode = fireNode.getChildByName('bg_broken'); const bgBrokenNode = fireNode.getChildByName('bg_broken');
if (bgFullNode) { if (bgFullNode) {
bgFullNode.active = false; bgFullNode.active = false;
} }
if (bgBrokenNode) { if (bgBrokenNode) {
bgBrokenNode.active = true; bgBrokenNode.active = true;
} }
// 如果不需要滚动,则直接从活跃列表中移除并隐藏节点 // 如果不需要滚动,则直接从活跃列表中移除并隐藏节点
if (!this.needScroll) { if (!this.needScroll) {
// 从活跃火苗列表中移除当前火苗 // 从活跃火苗列表中移除当前火苗
...@@ -449,7 +413,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -449,7 +413,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (index !== -1) { if (index !== -1) {
this.activeFireNodes.splice(index, 1); this.activeFireNodes.splice(index, 1);
} }
// 隐藏对应的fire节点 // 隐藏对应的fire节点
fireNode.active = false; fireNode.active = false;
} else { } else {
...@@ -486,11 +450,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -486,11 +450,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 确保火苗节点保持显示状态 // 确保火苗节点保持显示状态
if (fireNode) { if (fireNode) {
fireNode.active = true; fireNode.active = true;
// 更新糖果背景状态:显示bg_full,隐藏bg_broken // 更新糖果背景状态:显示bg_full,隐藏bg_broken
const bgFullNode = fireNode.getChildByName('bg_full'); const bgFullNode = fireNode.getChildByName('bg_full');
const bgBrokenNode = fireNode.getChildByName('bg_broken'); const bgBrokenNode = fireNode.getChildByName('bg_broken');
if (bgFullNode) { if (bgFullNode) {
bgFullNode.active = true; bgFullNode.active = true;
} }
...@@ -827,7 +791,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -827,7 +791,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (this.needScroll && this.layout && this.layout.childrenCount > 0) { if (this.needScroll && this.layout && this.layout.childrenCount > 0) {
// 移动糖果区域 // 移动糖果区域
this.layout.x -= this.scrollSpeed * dt; this.layout.x -= this.scrollSpeed * dt;
// 检查第一个糖果节点是否已经移出视图 // 检查第一个糖果节点是否已经移出视图
const firstCandy = this.layout.children[0]; const firstCandy = this.layout.children[0];
if (firstCandy && firstCandy.x + this.layout.x + firstCandy.width / 2 < -this.layout.parent.width / 2) { if (firstCandy && firstCandy.x + this.layout.x + firstCandy.width / 2 < -this.layout.parent.width / 2) {
...@@ -838,18 +802,18 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -838,18 +802,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.activeFireNodes.splice(index, 1); this.activeFireNodes.splice(index, 1);
} }
} }
// 从布局中移除第一个节点 // 从布局中移除第一个节点
firstCandy.removeFromParent(); firstCandy.removeFromParent();
firstCandy.destroy(); firstCandy.destroy();
// 如果有待添加的糖果数据,添加新的糖果节点 // 如果有待添加的糖果数据,添加新的糖果节点
if (this.pendingCandyData.length > 0) { if (this.pendingCandyData.length > 0) {
this.addNewCandyNode(); this.addNewCandyNode();
} }
} }
} }
// 移除了提示动画逻辑 // 移除了提示动画逻辑
} }
......
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