Commit 61b9b1a3 authored by Tt's avatar Tt

滚动列表完成

parent 1f40bad1
......@@ -400,7 +400,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// X坐标:从左到右排列,考虑间距,基于listItem的左边界
const itemX = listItem.ref.x + (column * (itemWidth + itemSpacing)) + (itemWidth / 2);
// Y坐标:从上到下排列,考虑间距,基于listItem的中心
const itemY = listItem.ref.y + (row * (itemHeight + itemSpacing)) + (itemHeight / 2) - (listHeight / 2);
const itemY = (row * (itemHeight + itemSpacing)) + (itemHeight / 2) - (listHeight / 2);
// 设置子节点位置和缩放
itemNode.ref.x = itemX;
......@@ -416,8 +416,8 @@ export class PlayComponent implements OnInit, OnDestroy {
textElement.ref.fontSize = 80 * this.g_mapScale;
textElement.ref.fontColor = '#000000';
// 设置文字位置与itemNode相同
textElement.ref.x = itemX;
textElement.ref.y = itemY;
textElement.ref.x = 0//itemX;
textElement.ref.y = 0//itemY;
// 设置文本对齐方式为居中
textElement.ref.textAlign = 'center';
......@@ -431,8 +431,10 @@ export class PlayComponent implements OnInit, OnDestroy {
};
// 渲染子节点和文字
this.render(itemNode.ref, zIndexMap.card);
this.render(textElement.ref, zIndexMap.card + 1);
itemNode.ref.addChild(textElement.ref)
listItem.ref.addChild(itemNode.ref);
// this.render(itemNode.ref, zIndexMap.card);
// this.render(textElement.ref, zIndexMap.card + 1);
}
// 添加滑动功能
......@@ -472,29 +474,13 @@ export class PlayComponent implements OnInit, OnDestroy {
let newX = listItemStartX + deltaX;
// 限制滑动范围,防止滑出边界 - 基于左锚点的边界计算
const minX = 0; // 左边界:列表左边缘不能超出画布左边
const maxX = this.g_canvasWidth - listWidth; // 右边界:列表右边缘不能超出画布右边
const minX = this.g_canvasWidth - listWidth; // 左边界:列表左边缘不能超出画布左边
const maxX = 0; // 右边界:列表右边缘不能超出画布右边
newX = Math.max(minX, Math.min(newX, maxX));
// 更新list_item位置
listItem.ref.x = newX;
// 更新所有子节点位置 - 基于新的listItem位置重新计算
for (let i = 0; i < totalItems; i++) {
const column = Math.floor(i / maxItemsPerColumn);
const row = i % maxItemsPerColumn;
const itemNode = this.g_cartoon.getCartoonElement(`list_item_${i}`);
const textElement = this.g_cartoon.getCartoonElement(`list_item_text_${i}`);
if (itemNode) {
const itemX = listItem.ref.x + (column * (itemWidth + itemSpacing)) + (itemWidth / 2);
itemNode.ref.x = itemX;
// 同时更新对应的文字位置
if (textElement) {
textElement.ref.x = itemX;
}
}
}
console.log("listItem.ref.x", listItem.ref.x)
}
// 重新启用移动事件
this.g_enableMapMove = true;
......
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